Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had to update a table i tried two queries but it shows syntax error can anyone help me pls I know this is basic but i am a begginer


C#
String query = "Update masterusertable set username='" + txtName.Text + "',and set password='" + txtpassword.Text + "',and set phoneno='" + txtphoneno.Text + "',and set adress='" + rtxtAdress.Text + "' where userid ='" + txtuserid.Text + "'";




String query = "Update masterusertable set username='" + txtName.Text + "', password='" + txtpassword.Text + "', phoneno='" + txtphoneno.Text + "', adress='" + rtxtAdress.Text + "' where userid ='" + txtuserid.Text + "'";


its shows oledbexception due to syntax error in update statement ,no the userid is text but unique NON DUPLICABLE
anyother idea i had many big tables to be updated is it good to update using anyother ideas
Posted
Updated 3-Feb-11 1:52am
v3
Comments
Prerak Patel 3-Feb-11 7:44am    
Don't forget to share the exact error. It would be much easier for us to help you in that way.

1 solution

Your second query looks good, but if userid is a numeric field, use following

C#
String query = "Update masterusertable set username='" + txtName.Text + "', password='" + txtpassword.Text + "', phoneno='" + txtphoneno.Text + "', adress='" + rtxtAdress.Text + "' where userid =" + txtuserid.Text;
 
Share this answer
 
Comments
SREENATH GANGA 3-Feb-11 7:51am    
its shows oledbexception due to syntax error in update statement ,no the userid is text but unique NON DUPLICABLE
Prerak Patel 3-Feb-11 7:56am    
Then your 2nd query is perfect by syntax. Check the field names, do they match perfectly. I can see "address" spelled wrong as "adress". Is it same in database? What is the exact error message? Any pointer to the error?
SREENATH GANGA 5-Feb-11 2:47am    
OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
oleDbConnection1.Open();
String query = "Update masterusertable set username='" + userdata.Username + "',password='" + userdata.Passsword + "',phoneno=" + userdata.Phone + ", adress='" + userdata.Adress1 + "' where userid ='" + userdata.Userid + "'";


OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand(query, oleDbConnection1);
oleDbCommand1.CommandType = CommandType.Text;

oleDbCommand1.ExecuteNonQuery();

oleDbConnection1.Close();
showdata12();
clearcontrol();

this was my code
error it points to
oleDbCommand1.ExecuteNonQuery();

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