问题
Trying to execute a delete query and getting the following error
Syntax error (missing operator) in query expression 'cname VALUES @cname'.
code
Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Settings.strFileName)
conn.Open()
Dim cmdText = "DELETE FROM products WHERE cname VALUES @cname"
Dim cmd As OleDbCommand = New OleDbCommand(cmdText, conn)
With cmd.Parameters
.Add(New OleDbParameter("@cname", DataGridView1.Item("cname", i).Value))
End With
Dim dt As New DataTable("products")
cmd.ExecuteNonQuery()
conn.Close()
conn = Nothing
回答1:
The way you wrote your delete statement is not correct.
You should write it like this:
Dim cmdText = "DELETE FROM products WHERE cname = @cname"
回答2:
You need an operator
DELETE FROM products WHERE cname = @cname
回答3:
And to delete all
record from a table with a specific ID
, you just have to;
deleteMore:
DELETE TOP(100) TableName WHERE toDelete='17'
IF @@ROWCOUNT != 0
goto deleteMore:
This will delete the first 100 records, and repeatedly until all records with 17
are gone.
来源:https://stackoverflow.com/questions/11769011/sql-delete-statement-syntax