HI all!
in c# when i write a query to update there occurs an error "Syntex Error in UPDATE query"
my code is as

  1. string query="UPDATE Employee_Table StartTime='"+txt_StartTime.Text+"',EndTime='"+txt_endTime.Text+"'where id="+txt_id.Text+";";

where Employee_Table is a table in Acces
the field StartTime is of date/time data types and EndTime is also date/time.

where is the syntax eror in my query................it is urgent please help me to solve this. Thanks

Please see these threads for information on using parameters:
http://www.daniweb.com/forums/thread191241.html
http://www.daniweb.com/forums/thread198304.html

You should use parameterized queries. It makes your code easier to read, is less security risk, and has better performance:

private void simpleButton1_Click(object sender, EventArgs e)
    {
      const string query = "Insert Into aTable (aString, aDateTime) Values (@aString, @aDateTime)";
      const string connStr = @"Data Source=apex2006sql;Initial Catalog=DB;Integrated Security=True;";
      using (SqlConnection conn = new SqlConnection(connStr))
      {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
          string s1 = "abc123";
          DateTime dtNow = DateTime.Now;
          cmd.Parameters.Add(new SqlParameter(@"aString", SqlDbType.VarChar)).Value = s1;
          cmd.Parameters.Add(new SqlParameter(@"aDateTime", SqlDbType.DateTime)).Value = dtNow;
          cmd.ExecuteNonQuery();
        }
        conn.Close();
      }
    }

You're most likely using OleDb so switch the Sql* to OleDb* and it should suit your needs.

Query missing SET.

Use this code if data type of ID is int (numeric).

string query="UPDATE Employee_Table SET
 StartTime='"+txt_StartTime.Text
+"',EndTime='"+txt_endTime.Text
 +"'  where id="+txt_id.Text;

Use this code if data type of ID is non-numeric

string query="UPDATE Employee_Table SET
 StartTime='"+txt_StartTime.Text
+"',EndTime='"+txt_endTime.Text
 +"'  where id='"+txt_id.Text + "'";

i have a problem in updating my records

the exception is:-
syntax error (missing operator) in query expression'2/2/2005 12:0:0 AM'.

can anybody help
thnx in advance

i have a problem in updating my records

the exception is:-
syntax error (missing operator) in query expression'2/2/2005 12:0:0 AM'.

can anybody help
thnx in advance

You should start a new thread with your specific issue. Please post the relevant code so we can help you. We can't help you fix something if we can't see whats broken :P

HI all!
in c# when i write a query to update there occurs an error "Syntex Error in UPDATE query"
my code is as

  1. string query="UPDATE Employee_Table StartTime='"+txt_StartTime.Text+"',EndTime='"+txt_endTime.Text+"'where id="+txt_id.Text+";";

where Employee_Table is a table in Acces
the field StartTime is of date/time data types and EndTime is also date/time.

where is the syntax eror in my query................it is urgent please help me to solve this. Thanks

Hi,
there is missing keyword "Set" in Update query
string query="UPDATE Employee_Table SET StartTime='"+txt_StartTime.Text+"',EndTime='"+txt_endTime.Text+"'where id="+txt_id.Text+";";

string query="UPDATE Employee_Table SET StartTime='"+txt_StartTime.Text+"',EndTime='"+txt_endTime.Text+"'" where id="+txt_id.Text+";

This wil absolutely work fine, i have used it few days back...

This article has been dead for over six months. Start a new discussion instead.