Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

try to include single qutation

 

something like this


OleDbDataAdapter1.DeleteCommand.CommandText = "DELETE *

FROM Daily WHERE Mainid =' " & intmain & " ' "



 

 

I hope it works

Gary Says: To be a good programmer, you must be good at debugging
  • *Experts*
Posted

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 = " & intmain

And see what it prints in the debug window.

  • Moderators
Posted

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.

Visit...Bassic Software

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