SQL DELETE statement syntax

北城余情 提交于 2019-12-25 05:06:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!