小白请教诸位个问题c#向SQL2008插入数据
刚刚开始学习C#,想自己编个向数据库插入数据的小程序,代码如下,但是点击button后提示成功,但是数据库里面并无所插入新数据,求解答,原因在哪,我是小白,谢谢诸位
private void button1_Click_1(object sender, EventArgs e)
{
string ID = "";
string name = "";
ID = textBox1.Text;
name = textBox2.Text;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=XUHUI\\SQLEXPRESS;Initial Catalog=ceshi;Persist Security Info=True;User ID=SA;Password=880610";
conn.Open();
string sqlinsert = "insert into ceshi(ID,name) values('" + ID + "','" + name + "')";
SqlCommand sc = new SqlCommand(sqlinsert,conn);
textBox1.Text = "";
textBox2.Text = "";
MessageBox.Show("数据已经添加成功", "温馨提示");
conn.Close();
------解决方案-------------------- SqlCommand sc = new SqlCommand(sqlinsert,conn);
sc.ExecuteNonQuery();
你都没有执行插入的操作
------解决方案--------------------
.ExecuteNonQuery();