Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Whenever I send an sql command to a connection using a number as a criteria, I always get an unhandled exception error right when I tell to Execute a Non query. I am using VB.NET and Microsoft Access as the database. Any help with this question would greatly be appriciated.
Posted

The copy of the code I am using is below:

 

Dim intnumber As Integer

intnumber = CInt(fldrecord.Text)

DataSet11.Clear()

OleDbDataAdapter1.DeleteCommand = New OleDb.OleDbCommand()

OleDbConnection1.Open()

OleDbDataAdapter1.DeleteCommand.Connection = OleDbConnection1

OleDbDataAdapter1.DeleteCommand.CommandText = "DELETE FROM FloorOpps WHERE mainid = '" & intnumber & "'"

OleDbDataAdapter1.DeleteCommand.ExecuteNonQuery()

OleDbDataAdapter1.Fill(DataSet11)

OleDbConnection1.Close()

 

The error I am getting is as follows:

 

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

 

I am getting the error at the code

OleDbDataAdapter1.DeleteCommand.ExecuteNonQuery()

 

It works fine when I am using a criteria based on text. However the mainid field in the database is not a text field it is an autonumber field and that is what is giving me the error. If it was a text field I would have no error. Any help you can give me would greatly be appreiciated.

Posted

Well If you are working with an Access database then this will help.

 

Access databases are very strict concerning syntax, if this were an SQL your code will work perfectly.

 

But in Access whenever you have a number that you need to pass your search criteria should not be surropunded by single quotes so you query should be "DELETE FROM FloorOpps WHERE mainid = " & intnumber

 

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...