0

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

3 Answers 3

4

You need an operator

DELETE FROM products WHERE cname = @cname
Sign up to request clarification or add additional context in comments.

Comments

3

The way you wrote your delete statement is not correct.

You should write it like this:

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

Comments

-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.