Unhandled Exception

lothos12345

Well-known member
Joined
May 2, 2002
Messages
294
Location
Texas
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.
 
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.
 
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,
 
Back
Top