Click here to Skip to main content
14,927,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to update table called customer with follwing query
C#
string Query = "UPDATE Customer SET Customer name=" + textBox2.Text +" WHERE Cnic=" + textBox9.Text;
               da1 = new OleDbDataAdapter(Query,con);
               dt1 = new DataTable();

da1.Fill(dt1);

biut i am getting syntax error exception.Kindly tell me what is the problem.
Posted
Comments
CHill60 13-Jun-13 13:20pm
   
Use the Improve question link to give details of the exception/syntax error

1 solution

You have to escape your string values:

C#
string Query = "UPDATE Customer SET Customer name='" + textBox2.Text +"' WHERE Cnic='" + textBox9.Text + "'";


Also, update statements don't return a data set, so you need to use an OleDbCommand and then use the ExecuteScalar or ExecuteNonQuery to run the update statement.
   
v2

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