diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx" new file mode 100644 index 0000000000000000000000000000000000000000..85d90e52379361d3bfd70f3646278488c9cea437 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx" @@ -0,0 +1,42 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Add.aspx.cs" Inherits="WebApplication1.Add" %> + + + + + + + + + +
+
+

添加

+ + + + + + + + + + + + + + + + + + + + +
姓名:
密码:
Email:
自我介绍:
+ +   + +
+
+
+ + diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx.cs" new file mode 100644 index 0000000000000000000000000000000000000000..15c4aa050292908fa572be558e3580a07f023701 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx.cs" @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace WebApplication1 +{ + public partial class Add : System.Web.UI.Page + { + private SqlHelper helper = new SqlHelper(); + protected void Page_Load(object sender, EventArgs e) + { + + } + + protected void Button1_Click(object sender, EventArgs e) + { + string name = TextBox1.Text; + string password = TextBox2.Text; + string email = TextBox3.Text; + string intro = TextBox4.Text; + + string sql = "insert into StudentInfo(stu_name,password,email,intro) values (@name,@pwd,@email,@intro)"; + + SqlParameter[] sqls = + { + new SqlParameter("@name",name), + new SqlParameter("@pwd",password), + new SqlParameter("@email",email), + new SqlParameter("@intro",intro) + }; + + if (helper.Execute(sql,sqls)==true) + { + Literal1.Text = "添加成功"+"去查看》》"; + } + + + } + } +} \ No newline at end of file diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx.designer.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx.designer.cs" new file mode 100644 index 0000000000000000000000000000000000000000..a37d63346fbfbedc977c487defb9b45b4f028395 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/Add.aspx.designer.cs" @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace WebApplication1 +{ + + + public partial class Add + { + + /// + /// form1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// + /// TextBox1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.TextBox TextBox1; + + /// + /// TextBox2 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.TextBox TextBox2; + + /// + /// TextBox3 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.TextBox TextBox3; + + /// + /// TextBox4 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.TextBox TextBox4; + + /// + /// Button1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button Button1; + + /// + /// Literal1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Literal Literal1; + } +} diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/SqlHelper.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/SqlHelper.cs" new file mode 100644 index 0000000000000000000000000000000000000000..a91f9cedaaf10a503df88e41ac7d9ff6c202c6e0 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/SqlHelper.cs" @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Web; + +namespace WebApplication1 +{ + public class SqlHelper + { + private string constr = "server=.;uid=sa;pwd=123456;database=Student_db"; + + private SqlConnection cot=null; + public SqlHelper() + { + cot = new SqlConnection(constr); + } + public DataTable Get(string sql,SqlParameter [] sqls) + { + try + { + if (cot.State==ConnectionState.Closed) + { + cot.Open(); + } + SqlCommand cmd = new SqlCommand(sql,cot); + if (sqls != null) + { + cmd.Parameters.AddRange(sqls); + } + SqlDataAdapter sdat = new SqlDataAdapter(cmd); + DataSet data = new DataSet(); + sdat.Fill(data); + return data.Tables[0]; + } + catch (Exception e) + { + throw new Exception(e.Message.ToString()); + } + finally + { + if (cot!=null) + { + cot.Close(); + } + } + } + + public bool Execute(string sql ,SqlParameter[] sqls) + { + try + { + if (cot.State == ConnectionState.Closed) + { + cot.Open(); + } + SqlCommand cmd = new SqlCommand(sql,cot); + if (sqls != null) + { + cmd.Parameters.AddRange(sqls); + } + + return cmd.ExecuteNonQuery() > 0 ? true : false; + } + catch (Exception e) + { + + throw new Exception(e.Message.ToString()); + } + finally + { + if (cot!=null) + { + cot.Close(); + } + } + } + } +} \ No newline at end of file diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx" new file mode 100644 index 0000000000000000000000000000000000000000..d07cec7f056cc4ce1dc938740306af4ba9578feb --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx" @@ -0,0 +1,35 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> + + + + + + + + + +
+
+ + + + + + + + + + + + 请输入你要查询的名字:  + +   + + +
+ + +
+
+ + diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b69a299e18a722b265e9b6942ee67c6462cfd8bf --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx.cs" @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace WebApplication1 +{ + public partial class WebForm1 : System.Web.UI.Page + { + private SqlHelper sqlHelper = new SqlHelper(); + protected void Page_Load(object sender, EventArgs e) + { + if (!IsPostBack) + { + Bind(); + } + } + private void Bind() + { + GridView1.DataSource = sqlHelper.Get("select * from StudentInfo",null); + GridView1.DataKeyNames = new string[] { "stu_id" }; + GridView1.DataSourceID = null; + GridView1.DataBind(); + } + + protected void Button1_Click(object sender, EventArgs e) + { + string name = TextBox1.Text; + + string sql = "select * from StudentInfo where stu_name like '%'+@name+'%'"; + + SqlParameter[] sql1 = {new SqlParameter("@name",name)}; + GridView1.DataSource = sqlHelper.Get(sql,sql1); + GridView1.DataBind(); + } + + protected void Button2_Click(object sender, EventArgs e) + { + Response.Redirect("Add.aspx"); + } + + protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) + { + GridView1.EditIndex = e.NewEditIndex; + Bind(); + } + + protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) + { + string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); + + string name = (GridView1.Rows[e.RowIndex].Cells[0].Controls[0] as TextBox).Text; + string email = (GridView1.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox).Text; + string intro = (GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text; + string password = (GridView1.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox).Text; + + string sql = "update StudentInfo set stu_name=@name,email=@email,intro=@intro,password=@pwd where stu_id=@id"; + SqlParameter[] sqls = + { + new SqlParameter("@name",name), + new SqlParameter("@email",email), + new SqlParameter("@intro",intro), + new SqlParameter("@pwd",password), + new SqlParameter("@id",id) + }; + if (sqlHelper.Execute(sql,sqls)) + { + GridView1.EditIndex = -1; + Bind(); + } + else + { + Response.Write(""); + } + } + + protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) + { + GridView1.EditIndex = -1; + Bind(); + } + + protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) + { + string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); + + string sql = "delete from StudentInfo where stu_id=@id"; + + SqlParameter[] sqls = { new SqlParameter("@id", id) }; + + if (sqlHelper.Execute(sql,sqls)) + { + Bind(); + } + else + { + Response.Write(""); + } + } + } +} \ No newline at end of file diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx.designer.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx.designer.cs" new file mode 100644 index 0000000000000000000000000000000000000000..102f5fbfe6bb68f3348877c3f30db6e7930e77b6 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/WebForm1.aspx.designer.cs" @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace WebApplication1 +{ + + + public partial class WebForm1 + { + + /// + /// form1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// + /// GridView1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.GridView GridView1; + + /// + /// SqlDataSource1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.SqlDataSource SqlDataSource1; + + /// + /// TextBox1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.TextBox TextBox1; + + /// + /// Button1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button Button1; + + /// + /// Button2 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button Button2; + + /// + /// Literal1 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Literal Literal1; + } +}