You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VB.NET中使用Dapper操作Access数据库的保留字(如name)

在VB.NET中使用Dapper操作Access数据库保留字的解决方案

Access数据库的保留字(如name)需要用**方括号[]**包裹,才能让数据库正确识别为字段名称而非关键字,无需修改原字段名。针对你的代码,只需调整SQL语句中的保留字段名即可:

修改后的代码

Con.Execute($"Update Users Set [name] = @name, email = @email, phone = @phone, password = @password Where id = @id", New With {
    Key .name = bunifuTextBox1.Text,
    Key .email = txtEmail.Text,
    Key .phone = bunifuTextBox2.Text,
    Key .password = txtPassword.Text,
    Key .id = id
})

关键说明

  • 将SQL语句中的name替换为[name],这是Access处理保留字的标准语法
  • 你原代码中Set name = name是无效赋值(将字段值设为自身),修正为[name] = @name后才能正确传递参数值更新字段
  • Dapper的参数映射不受影响,参数名.name仍能和@name正确绑定

内容的提问来源于stack exchange,提问作者roy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 04:01:20