Jaspreet Kaur

Jaspreet Kaur

  • NA
  • 7
  • 3.1k

please trace an error in the following code?

Jun 21 2012 6:42 AM
please help,, this particular code has become headache for me!!! i coudnt get it " where m i wrong???please trace an error in the following code. this is simple code to update data,, i dont know y it is giving "Syntax error in UPDATE statement."

OleDbConnection con = new OleDbConnection();
con.ConnectionString = connection.connstring;
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText ="update info set city=@a,cname=@b,contactno=@c,add=@d,pincode=@e where fname='" + comboBox1.Text + "'";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@a", comboBox2.Text);
cmd.Parameters.AddWithValue("@b", textBox1.Text);
cmd.Parameters.AddWithValue("@c", textBox2.Text);
cmd.Parameters.AddWithValue("@d", richTextBox1.Text);
cmd.Parameters.AddWithValue("@e", textBox3.Text);

int i = cmd.ExecuteNonQuery();

if (i > 0)
{
MessageBox.Show("data is updated");
}
thanks in advance!!


Answers (2)