使用c#更新访问中的数据库记录时出现问题

时间:2017-08-12 09:48:58

标签: c# ms-access sql-update

我正在使用存储客户数据的程序 后来需要改变

这是我的代码:

private void button2_Click(object sender, EventArgs e)       
{
        conn.Open();
        string oc = ("Update Custs Set Cname =@Cname, NatCode=@NatCode, Bdate=@Bdate, CellPhone=@CellPhone, Addr=@Addr,  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!");

        }

但它没有做任何改变

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

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

<{1>} myCommand.Parameters.AddWithValue("@Bdate", textBox2.Text); textBox2 Birthday用于NationalCode,而在查询中,您将其用于+x

我想问题就在于它。

相关问题