C#Access数据库更新语法错误

时间:2017-06-04 13:47:47

标签: c# sql ms-access

此查询有问题吗?

"UPDATE tb_EmployeeMasterList SET [EmployeeID] = " + txt_EmpId.Text +", [LastName] = '" + txt_LN.Text + "', [FirstName] = '" + txt_FN.Text + "', [MiddleName] = '" + txt_MN.Text + "', [PositionOrSkill] = '" + txt_PorS.Text + "', [BasicSalary] = " + txt_Basic.Text + ", [Allowance] = " + txt_Allow.Text + ", [Total] = " + total + ", [EPAproposedBonus] = " + txt_Bonus.Text + ", [Remarks] = '" + txt_Remarks.Text + "' WHERE ([LastName] = '" + LN + "' AND [FirstName] = '" + FN + "');"

我继续单独在该查询上获取语法错误。

3 个答案:

答案 0 :(得分:0)

似乎缺少一对单引号:

"UPDATE tb_EmployeeMasterList SET [EmployeeID] = " + txt_EmpId.Text +",

应该是:

"UPDATE tb_EmployeeMasterList SET [EmployeeID] = '" + txt_EmpId.Text +"', 

答案 1 :(得分:0)

尝试触发不带括号的WHERE语句

"UPDATE tb_EmployeeMasterList SET [EmployeeID] = " + txt_EmpId.Text +", [LastName] = '" + txt_LN.Text + "', [FirstName] = '" + txt_FN.Text + "', [MiddleName] = '" + txt_MN.Text + "', [PositionOrSkill] = '" + txt_PorS.Text + "', [BasicSalary] = " + txt_Basic.Text + ", [Allowance] = " + txt_Allow.Text + ", [Total] = " + total + ", [EPAproposedBonus] = " + txt_Bonus.Text + ", [Remarks] = '" + txt_Remarks.Text + "' WHERE [LastName] = '" + LN + "' AND [FirstName] = '" + FN + "';"

答案 2 :(得分:0)

如果totalLNFN值来自变量而不是文本框,那么语法就可以了,但Textbox会在它们之后添加.Text,否则会出现语法错误。