Click here to Skip to main content
15,883,888 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hay there again Im trying to update some small stuff in a access database using the OleDb.
Know I have this code:

C#
string command = ("UPDATE Users SET Id="+"'"+user+"'"+", User="+"'"+password+"'"+"WHERE Id="+"<"+Opassword+">");
            c = new OleDbCommand(command, con);
            ap.UpdateCommand = c;
            con.ConnectionString = conection;
            using(con)
            {
                c.Connection = con;
                con.Open();
                ap.UpdateCommand.ExecuteNonQuery();                
            }
            ap.Dispose();
            con.Close();


Know the onle error I receive is a simple "You had a Sysntax error on your UPDATE command" it doesnt sepecify in what it simply doesnt execute it.

How may I fix this, or what is the correct way to deal with this ?
Posted
Updated 1-Feb-12 15:29pm
v2
Comments
walterhevedeich 1-Feb-12 21:30pm    
is 0password really a variable or just a typo on your part?
Kethu Sasikanth 1-Feb-12 21:58pm    
The sql seem confusing to me. First comment out the whole sql then try just hardcoded sql. ex: UPDATE users SET Id='xx', User='yyy' where id=... If this executes correctlty then problem is in below lines otherwise the problem is in sql construction.
Mycroft Holmes 1-Feb-12 22:38pm    
What is the database you are using?
Member 8437747 3-Feb-12 13:32pm    
Opassw0ord is a varible, is used to represent the old user password.
I´m using an access database.

1 solution

Assuming you are using SQL server!
Put a break point in your code and look at the string you are trying to execute.
Copy the string to SSMS and try and execute it.

I suspect the use of "<"+Opassword+">" instead of "["+Opassword+"]" may be the error. Or one of your variables is incorrect or missing.

Learn how to use prameterised queries, they will make you life DRAMATICALLY simpler.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900