【问题标题】:updating query to read from Microsoft access database更新查询以从 Microsoft 访问数据库中读取
【发布时间】:2015-04-04 17:07:35
【问题描述】:

大家好,我在从 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();

【问题讨论】:

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


    【解决方案1】:

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

    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 没有任何意义,因为它不会改变。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-28
      相关资源
      最近更新 更多