c# - 我的 MS Access 更新查询有什么问题?

标签 c# ms-access

这是我的查询:

string Select = "Update DC set Password = '" + txtPass.Text + "' WHERE ID ="+Convert.ToInt32(cbxDocs.SelectedIndex + 1);
con = new OleDbConnection();
this.readconfile = new ReadConfigFile();
con.ConnectionString = this.readconfile.ConfigString(ConfigFiles.ProjectConfigFile);
con.Open();
cmd = new OleDbCommand(Select, con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();

我不知道出了什么问题,但它给了我一条错误消息“UPDATE STATEMENT 中的语法错误”。 我的表“DC”ID 和密码中有两个字段,没有其他字段。

最佳答案

密码 is reserve word将其括在方括号中,例如 [Password],因此您的查询应以如下方式开头:

"Update DC set [Password]....

考虑使用参数化查询,这将使您免于 Sql Injection

关于c# - 我的 MS Access 更新查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17620994/

相关文章:

c# - 表单设计器 View 在 Visual Studio 2019 C# CMake 项目中不可用

C# Enumerable.Take 带默认值

forms - 是否可以运行仅影响连续形式中的一行的 VBA 代码?

ms-access - 微软 Access : How to delete the selected item from Combobox when button pressed?

sql - MS Access 更新区号

c# - Dictionary<> 中的条目是否有限制?

c# - 我们如何使用第三方 API 为 Webapi 创建单元测试

c# - 在 ASP.NET Core Blazor 中使用 MongoDB 作为服务

excel - Access 换行符成为_x000D_

java - Java中如何将字符串值转换为日期?