我正在尝试制作一些代码,如果该项已经存在则会更新一行。它看起来像这样:
updateStr = "UPDATE platinum_paste SET ([aluminium], [calcium], [chrome], [iron], [lead], [silicon], [zirconium]) VALUES (" & aluminium & "," & _
calcium & "," & _
chrome & "," & _
iron & "," & _
lead & "," & _
silicon & "," & _
zirconium & _
") WHERE [lot_number] = " & lotNumber
Debug.Print updateStr
If MsgBox("Item already exists. Do you want to update its details?", vbYesNo) = vbYes Then
objMyConn.Execute updateStr, dbFailOnError
Else
'Do nothing
End If
当我尝试运行它时,单击"是"在MsgBox中将导致错误:
运行时错误' -2147217900(80040e14)':
自动化错误
谁能告诉我我做错了什么?我试图添加我能想到的所有可能的调试功能。数据库连接适用于SELECT
和INSERT
。这是我的INSERT
字符串,它可以正常工作:
insertStr = "INSERT INTO platinum_paste ([lot_number], [aluminium], [calcium], [chrome], [iron], [lead], [silicon], [zirconium]) VALUES (" & lotNumber & "," & _
aluminium & "," & _
calcium & "," & _
chrome & "," & _
iron & "," & _
lead & "," & _
silicon & "," & _
zirconium & ")"
答案 0 :(得分:3)
UPDATE
- 字符串的语法错误。你需要写
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
有关详细信息,请查看 http://www.w3schools.com/sql/sql_update.asp