SQL DELETE语句语法

时间:2012-08-01 23:27:37

标签: sql vb.net sql-delete

尝试执行删除查询并收到以下错误

  

查询表达式'cname VALUES @cname'中的语法错误(缺少运算符)。

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

3 个答案:

答案 0 :(得分:4)

您需要一名操作员

DELETE FROM products WHERE cname = @cname

答案 1 :(得分:3)

您编写删除语句的方式不正确。

你应该这样写:

Dim cmdText = "DELETE FROM products WHERE cname = @cname"

答案 2 :(得分:-1)

要从具有特定delete all的表格中ID记录,您只需要;

deleteMore:
DELETE TOP(100) TableName WHERE toDelete='17'
IF @@ROWCOUNT != 0
    goto deleteMore:

这将删除前100条记录,并重复删除,直到所有17的记录都消失。