更新查询以从Microsoft Access数据库中读取

时间:2015-04-04 17:07:35

标签: c# ms-access visual-studio-2012 visual-studio-2013 ms-access-2013

你好我们有从Microsoft Access 2013运行更新查询的问题我只想更新客户端表与客户端ID和名称和手机我不能得到数据更新始终错误的语法

string I = "UPDATE client SET client.ID =" + ID.Text + " ,client.Name =" + Name.Text + " ,client.Phone = " + Phone.Text + " WHERE client.ID="+ ID.Text +"";
            command.CommandText = I;
            command.CommandType = CommandType.Text;
            connection.Open();
            command.ExecuteNonQuery();

1 个答案:

答案 0 :(得分:0)

您需要使用参数化查询,如下所示:

string I = "UPDATE client SET client.Name = ?, client.Phone = ? WHERE client.ID = ?";
command.CommandText = I;
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("?", Name.Text);
command.Parameters.AddWithValue("?", Phone.Text);
command.Parameters.AddWithValue("?", ID.Text);
connection.Open();
command.ExecuteNonQuery();

请注意,“SET”client.ID没有意义,因为它不会改变。