lothos12345 Posted November 3, 2003 Posted November 3, 2003 I have created a program in VB.NET that looks into a Microsoft Access Database table and can delete a record based on what the user inputs into a textbox. An example of my code is below: OleDbDataAdapter1.DeleteCommand.CommandText = "DELETE * FROM Daily WHERE Mainid =" & intmain intmain contains a numeric value which is the primary key in the database the primary key is an Autonumber. Intmain gets its number value from a textbox on the program. The problem lies in the fact that when a user enters a number that is a record in the database it says the record does not exist when it obviously does. Any help would be greatly apprieciated. Quote
loyal Posted November 3, 2003 Posted November 3, 2003 try to include single qutation something like this OleDbDataAdapter1.DeleteCommand.CommandText = "DELETE * FROM Daily WHERE Mainid =' " & intmain & " ' " I hope it works Quote Gary Says: To be a good programmer, you must be good at debugging
*Experts* Volte Posted November 3, 2003 *Experts* Posted November 3, 2003 That wouldn't work, assuming Mainid is a number. Single quotes are for strings. I suggest putting the following line about the conflicting line:System.Diagnostics.Debug.WriteLine "DELETE * FROM Daily WHERE Mainid = " & intmainAnd see what it prints in the debug window. Quote
Moderators Robby Posted November 5, 2003 Moderators Posted November 5, 2003 Why not just issue an ExecuteNonQuery command? The problem with OleDbDataAdapter1.DeleteCommand.CommandText = "Delete..." is that at the time of assigning this command the variable intmain may not have the expected value. Folow Volte's example but do so at the same place that you assign the DeleteCommand. Quote Visit...Bassic Software
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.