user6579928
user6579928

Reputation:

Incorrect SQL syntax error

I have a SQL statement to delete a record from a database table. After stepping through it, I can see that it all works correctly, except for the final part (that is to say, it correctly gets the desired row to delete and all variables match the values that they should be). I'm new to using SQL, so can anybody tell me how to fix the following error at all?

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: Incorrect syntax near '*'.

SQL query:

Public Shared Sub deleteRecord(ByVal recordID As Integer, con As OleDbConnection)
    Dim Dc As New OleDbCommand
    Dc.Connection = con

    con.Open()
    Dc.CommandText = "DELETE * FROM tblData WHERE([recordID] =  '" & recordID & "')"

    Dc.ExecuteNonQuery()
    con.Close()

End Sub

Upvotes: 0

Views: 105

Answers (3)

StackOverflowGuest
StackOverflowGuest

Reputation: 41

Just remove the * and the parentheses. DELETE FROM tblData WHERE recordID = ...

Upvotes: 3

Aaron Dietz
Aaron Dietz

Reputation: 10277

* is used in lieu of typing out all of the column names you want to SELECT. The important thing to note here is that it represents columns.

DELETE occurs against rows. Therefore, saying DELETE * does not make any sense. You can't delete single columns/cells in this way.

Correct syntax is DELETE FROM [TABLE] WHERE [FILTERS]

Upvotes: 1

Dimitri
Dimitri

Reputation: 7013

replace with this:

Dc.CommandText = "DELETE FROM tblData WHERE [recordID] = " & recordID

Upvotes: 1

Related Questions