A problem to Delete a Record

jotaeva

Member
Joined
Sep 2, 2009
Messages
8
Programming Experience
Beginner
Hello:

I have a very strange problem. I need to delete a record after a payment in a Visual Studio 2005 App. and I am using this:

VB.NET:
...code....
cmd = con.CreateCommand
cmd.Connection = con
cmd.CommandText = "DELETE From meses where IDal = " & vId & " AND mesactual = ' " & vMes & " '"
cmd.ExecuteNonQuery()
...code...

vMes is a string and IDal it is Integer. As much vID as vMes are valid. Properly proven. The fields in DB are also valid and proven.

If I am about eliminating the registration with only one of the variables, it works but with both it doesn't delete record. I think the code is correct but I don't know what happen.

Could they help me please? Thank you in advance.

I am working with Access DB.
 
Is that your actual code? If so then you're putting spaces into the mesactual value. You have a space between your single quotes and your double quotes.

Never use string concatenation to insert variables into SQL code. ALWAYS use parameters and you won't encounter issues like this. Follow one of the blog links in my signature and you'll find another post on the topic of ADO.NET parameters.
 
Back
Top