lothos12345 Posted September 18, 2003 Posted September 18, 2003 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. Quote
Administrators PlausiblyDamp Posted September 18, 2003 Administrators Posted September 18, 2003 What exception do you get? Any chance you could post a code sample? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
lothos12345 Posted September 18, 2003 Author Posted September 18, 2003 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. Quote
Mehyar Posted September 19, 2003 Posted September 19, 2003 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, Quote Dream as if you'll live forever, live as if you'll die today
lothos12345 Posted September 19, 2003 Author Posted September 19, 2003 Thank You You suggestion worked perfectly thank you very much for the help. Quote
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.