2017-08-12 106 views
0

我与存储客户数据 程序工作,后来它需要改变麻烦在用C#

此访问更新数据库记录是我的代码:

private void button2_Click(object sender, EventArgs e)  
{ 
     conn.Open(); 
     string oc = ("Update Custs Set Cname [email protected], [email protected], [email protected], [email protected], [email protected], Where NatCode Like'%" + textBox2.Text + "%'"); 

     OleDbCommand myCommand = new OleDbCommand(); 
     myCommand.CommandText = oc; 
     myCommand.Connection = conn; 
     myCommand.Parameters.AddWithValue("@Cname",textBox1.Text); 
     myCommand.Parameters.AddWithValue("@NatCode", textBox3.Text); 
     myCommand.Parameters.AddWithValue("@Bdate", textBox2.Text); 
     myCommand.Parameters.AddWithValue("@CellPhone", textBox4.Text); 
     myCommand.Parameters.AddWithValue("@Addr", textBox8.Text); 

     myCommand.ExecuteNonQuery(); 

     conn.Close(); 
     MessageBox.Show("Data Changed successfully!"); 

     } 

但它不”做T改变任何东西

任何帮助,将不胜感激

+0

我想知道为什么你在这里有这么多大括号 - 这是复制和粘贴错误? –

+0

你以前昏迷哪里还有Like之后没有空间。也把参数放在参数中。 – mybirthname

+2

可能只是我的意见,但对我来说,通过'textBox8'命名文本框'textBox1'是一个糟糕的选择......为什么不根据它们应该包含的内容来命名这些文本? (也注意到方法名称中的'button2') – Rafalon

回答

0

确定Where NatCode Like'%" + textBox2.Text + "%'"包含任何行?

in myCommand.Parameters.AddWithValue("@Bdate", textBox2.Text);您正在使用textBox2Birthday而在查询中使用它为NationalCode

我想问题是这样的。