954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Syntex error in UPDATE Query C#---MS ACCESS

HI all!
in c# when i write a query to update there occurs an error "Syntex Error in UPDATE query"
my code is asstring 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

ejazmusavi
Light Poster
42 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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.

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

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 + "'";
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

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

fafi_ali
Light Poster
30 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

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 anew 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

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 
HI all! in c# when i write a query to update there occurs an error "Syntex Error in UPDATE query" my code is as
  • 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_TableSET StartTime='"+txt_StartTime.Text+"',EndTime='"+txt_endTime.Text+"'where id="+txt_id.Text+";";

GajananMurtikar
Newbie Poster
1 post since Jun 2009
Reputation Points: 10
Solved Threads: 0
 
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...

arunkumars
Junior Poster
186 posts since Jul 2009
Reputation Points: 26
Solved Threads: 22
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You