Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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()

  • Moderators
Posted

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.

Visit...Bassic Software
Posted

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,

Dream as if you'll live forever, live as if you'll die today

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...