尝试从数据库中删除数据时收到此错误。
附加信息:查询表达式中的语法错误(缺少运算符)' [项目ID] 1'。
有人可以帮忙吗?感谢。
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
'Check for the selected item in the list
If Me.dgvData.Rows.Count > 0 Then
If Me.dgvData.SelectedRows.Count > 0 Then
Dim intItemID As Integer = Me.dgvData.SelectedRows(0).Cells("Item ID").Value
'Open the connection
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
'Delete data
Dim cmd As New OleDb.OleDbCommand
cmd.Connection = cnn
cmd.CommandText = "DELETE FROM Product WHERE [Item ID]" & intItemID
cmd.ExecuteNonQuery()
'Refresh the data
Me.RefreshData()
'Close the connection
cnn.Close()
End If
End If
End Sub
结束班
答案 0 :(得分:0)
change cmd.CommandText = "DELETE FROM Product WHERE [Item ID]" & intItemID
到
cmd.CommandText = "DELETE FROM Product WHERE [Item ID] = " & intItemID
你忘记了等号