有誰能夠告訴我,爲什麼下面的代碼產生錯誤:附近有語法錯誤「(」
cQueryIS = "UPDATE Additional (StaffEUPN, Class, Additional1, Additional2, Additional3, Additional4,AdditionalLarge1, AdditionalLarge2, AdditionalLarge3, AdditionalLarge4) "
cQueryIS &= "VALUES (@cSTEupn, @cClass, @cAdditional1, @cAdditional2, @cAdditional3, @cAdditional4, @cAdditionalLarge1, @cAdditionalLarge2, @cAdditionalLarge3, @cAdditionalLarge4) "
cQueryIS &= "WHERE StaffEUPN = '" & cStaffEUPN & "' AND Class = '" & cClass & "'"
然而此代碼的工作:
cQueryIS = "UPDATE Additional SET [email protected], [email protected],
[email protected], [email protected], [email protected],
[email protected], [email protected],
[email protected], [email protected],
[email protected] "
cQueryIS &= "WHERE StaffEUPN = '" & cStaffEUPN & "' AND Class = '"
& cClass & "'"
我有點困惑,因爲我做的方式它首先在INSERT
命令上正常工作,僅在UPDATE
上導致錯誤。
以下是其餘代碼:
Using dbConnectionSQL As New SqlConnection(dbConnectionString)
Using comm As New SqlCommand()
With comm
.Connection = dbConnectionSQL
.CommandType = CommandType.Text
.CommandText = cQueryIS
.Parameters.AddWithValue("@cSTEupn", cStaffEUPN)
.Parameters.AddWithValue("@cClass", cClass)
.Parameters.AddWithValue("@cAdditional1", ProvisionAdditional(1))
.Parameters.AddWithValue("@cAdditional2", ProvisionAdditional(2))
.Parameters.AddWithValue("@cAdditional3", ProvisionAdditional(3))
.Parameters.AddWithValue("@cAdditional4", ProvisionAdditional(4))
.Parameters.AddWithValue("@cAdditionalLarge1", ProvisionAdditional(5))
.Parameters.AddWithValue("@cAdditionalLarge2", ProvisionAdditional(6))
.Parameters.AddWithValue("@cAdditionalLarge3", ProvisionAdditional(7))
.Parameters.AddWithValue("@cAdditionalLarge4", ProvisionAdditional(8))
End With
Try
dbConnectionSQL.Open()
comm.ExecuteNonQuery()
Catch ex As SqlException
WriteToLogFile("Update Additional", ex.Message.ToString())
MsgBox("Update Additional - " & ex.Message.ToString())
Exit Sub
End Try
End Using
End Using
因爲你混合了'insert'和'update'語法。 –
您的意思是VALUES方式只能用於INSERT命令嗎? –
更新命令必須使用'SET = ,...',而插入可以使用VALUES語法 –
Charleh