Delete Command

lothos12345

Well-known member
Joined
May 2, 2002
Messages
294
Location
Texas
I am trying to execute a delete command put it is throwing an unexpected exception at the nonquery line. I have no ideal why I have posted the code I am using below. Any help is greatly appreciated.

Dim delStr As String
MessageBox.Show("Are you sure you wish to delete this record?", "Deletion", MessageBoxButtons.OKCancel)
DataSet11.Clear()
objConnection = New OleDb.OleDbConnection()
objConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & "\\Wcmazda\database folder\DailyFloorOpps\AllStoresDB\DailyFloorOpps.mdb"
delStr = "DELETE * FROM FloorOpps WHERE mainid = " & fldrecord.Text & ""
objConnection.Open()
objAdapter.DeleteCommand = New OleDb.OleDbCommand()
objAdapter.DeleteCommand.Connection = objConnection
objAdapter.DeleteCommand.CommandText = delStr
objAdapter.DeleteCommand.ExecuteNonQuery() <---- Error
objAdapter.Fill(DataSet11, "FloorOpps")
objConnection.Close()
 
What type of field is mainid? Verify that its a string, and if its not, remove the single quotes.
 
First of all if the user clicks Cancel on the messageBox it will still go into the rest of the code.

To run any ExecuteNonQuery you dont need the DeleteCommand of the DataAdapter, you only need the OleDbCommand object.
 
The problem is that you are using a wrong syntax for the delete statement.

Set you delstr to
"DELETE FROM FloorOpps WHERE mainid = " & fldrecord.Text & ""
Not delete *

Robby and VolteFace have given great points fix them before you continue on your program.

Hope this helps,
 
Back
Top