Reputation: 1
I'm trying to delete an Item in my Access Database with vb.net
my code is:
Dim DString As String = "DELETE * FROM studentTable WHERE ID='" & DataGridView1.SelectedRows.Item(0).Cells(0).Value & "'"
Dim DCMD As New OleDbCommand(DString, con)
DCMD.ExecuteNonQuery()
Fill()
the code is working fine, my Problem is it's not working because my "ID" Row is set to AutoIncrement. What can I do to fix??
King regards
Upvotes: 0
Views: 676
Reputation: 2339
You have a syntax error in your SQL. You do not need a projection (column list) for a DELETE statement.
Try removing the * such as:
DELETE FROM studentTable WHERE ID=....
Also you do not need to quote numeric values with the apostrophe character (I don't think it will hurt).
You might also want to consider using a parameterized query instead of embedding the value.
Upvotes: 2