0

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

查询表达式“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
4

3 回答 3

4

你需要一个接线员

DELETE FROM products WHERE cname = @cname
于 2012-08-01T23:28:44.607 回答
3

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

你应该这样写:

Dim cmdText = "DELETE FROM products WHERE cname = @cname"
于 2012-08-01T23:29:05.590 回答
-1

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

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

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

于 2012-08-12T14:49:15.443 回答