lothos12345 Posted September 16, 2003 Posted September 16, 2003 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() Quote
*Experts* Volte Posted September 16, 2003 *Experts* Posted September 16, 2003 What type of field is mainid? Verify that it's a string, and if it's not, remove the single quotes. Quote
Moderators Robby Posted September 16, 2003 Moderators Posted September 16, 2003 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 don't need the DeleteCommand of the DataAdapter, you only need the OleDbCommand object. Quote Visit...Bassic Software
Mehyar Posted September 17, 2003 Posted September 17, 2003 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, Quote Dream as if you'll live forever, live as if you'll die today
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.