为何button2_Click按钮(修改)执行不了;但是button1_Click(增加)按钮可以执行; 求具体怎么改 20
privatevoidForm1_Load(objectsender,EventArgse){SqlConnectioncon=newSqlConnection();co...
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\NEWSQL;DataBase=FastFood;Integrated Security=True";
SqlCommand com = new SqlCommand();
com.CommandText = "Select * from Customer";
com.Connection = con;
con.Open();
SqlDataReader dr = com.ExecuteReader();
bindingSource1.DataSource = dr;
dataGridView1.DataSource = bindingSource1;
dr.Close();
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\NEWSQL;DataBase=FastFood;Integrated Security=True";
SqlCommand com = new SqlCommand();
com.CommandText = "insert into Customer values('2010006','天鸳','***','海德堡','南京西路','16952364782','baihe@yahoo.com','爱哭')";
com.Connection = con;
con.Open();
com.ExecuteNonQuery();
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\NEWSQL;DataBase=FastFood;Integrated Security=True";
SqlCommand com = new SqlCommand();
com.CommandText = "update Customer set UserName='张伟' where CustomerID=2010007";
com.Connection = con;
con.Open();
com.ExecuteNonQuery();
con.Close();
} 展开
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\NEWSQL;DataBase=FastFood;Integrated Security=True";
SqlCommand com = new SqlCommand();
com.CommandText = "Select * from Customer";
com.Connection = con;
con.Open();
SqlDataReader dr = com.ExecuteReader();
bindingSource1.DataSource = dr;
dataGridView1.DataSource = bindingSource1;
dr.Close();
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\NEWSQL;DataBase=FastFood;Integrated Security=True";
SqlCommand com = new SqlCommand();
com.CommandText = "insert into Customer values('2010006','天鸳','***','海德堡','南京西路','16952364782','baihe@yahoo.com','爱哭')";
com.Connection = con;
con.Open();
com.ExecuteNonQuery();
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\NEWSQL;DataBase=FastFood;Integrated Security=True";
SqlCommand com = new SqlCommand();
com.CommandText = "update Customer set UserName='张伟' where CustomerID=2010007";
com.Connection = con;
con.Open();
com.ExecuteNonQuery();
con.Close();
} 展开
2015-09-30
展开全部
加断点调试,输出sql语句,在sql中执行看看效果,确定是否数据库的相关表名等弄错了。
追问
具体怎么改;我是新手
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询