积极答复者
怎样将一个文本框的值插入到数据库中?

问题
答案
-
protected void Button1_Click(object sender, EventArgs e) { string Id = this.TextBox1.Text; string Name = this.TextBox2.Text; // 添加数据 this.AddEmployee(Id, Name); } public void AddEmployee(string fEmployeeId, string fName) { // 假个定数据表为以下结构, 你还可以下载 PetShop 4.0 的源代码示例 // 表名 Employee // Id nvarchar(50 not null // Name nvarchar(50) not null using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=myDataBase;Integrated Security=SSPI;")) { SqlCommand comm = new SqlCommand("INSERT INTO Employee (Id, Name) VALUES (@Id, @Name);", conn); comm.Parameters.Add("@Id", fEmployeeId); comm.Parameters.Add("@Name", fName); conn.Open(); comm.ExecuteNonQuery(); } }
知识改变命运,奋斗成就人生!- 已标记为答案 youer3 2009年8月15日 8:22
-
全部回复
-
protected void Button1_Click(object sender, EventArgs e) { string Id = this.TextBox1.Text; string Name = this.TextBox2.Text; // 添加数据 this.AddEmployee(Id, Name); } public void AddEmployee(string fEmployeeId, string fName) { // 假个定数据表为以下结构, 你还可以下载 PetShop 4.0 的源代码示例 // 表名 Employee // Id nvarchar(50 not null // Name nvarchar(50) not null using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=myDataBase;Integrated Security=SSPI;")) { SqlCommand comm = new SqlCommand("INSERT INTO Employee (Id, Name) VALUES (@Id, @Name);", conn); comm.Parameters.Add("@Id", fEmployeeId); comm.Parameters.Add("@Name", fName); conn.Open(); comm.ExecuteNonQuery(); } }
知识改变命运,奋斗成就人生!- 已标记为答案 youer3 2009年8月15日 8:22
-
看主键重复部分http://social.microsoft.com/Forums/zh-CN/295/thread/6b86cb92-b0f5-4131-9e07-066aeacfed0d
知识改变命运,奋斗成就人生! -
ListView 示例,你可以重新创建 ListView 的 Items 来刷新显示
知识改变命运,奋斗成就人生! -