my code update record if exists in database else insert new record.
my code follows:
protected void button3_click(object sender, eventargs e) { odbcconnection myconnection = new odbcconnection("driver={mysql odbc 3.51 driver};server=localhost;database=testcase;user=root;password=root;option=3;"); myconnection.open(); string mystring = "select fil_no,orderdate temp_save fil_no=? , orderdate=?"; odbccommand mycmd = new odbccommand(mystring, myconnection); mycmd.parameters.addwithvalue("", hiddenfield4.value); mycmd.parameters.addwithvalue("", textbox3.text); using (odbcdatareader myreader4 = mycmd.executereader()) { //** if (myreader4.read()) { string mystring1 = "update temp_save set order=? fil_no=? , orderdate=?"; odbccommand mycmd1 = new odbccommand(mystring1, myconnection); mycmd1.parameters.addwithvalue("", editor1.content.tostring()); mycmd1.parameters.addwithvalue("", hiddenfield1.value); mycmd1.parameters.addwithvalue("", textbox3.text); mycmd1.executenonquery(); } else { // set sql string string strsql = "insert temp_save (fil_no,order,orderdate) " + "values (?,?,?)"; // create command , set properties odbccommand objcmd = new odbccommand(strsql, myconnection); objcmd.parameters.addwithvalue("", hiddenfield4.value); objcmd.parameters.addwithvalue("", editor1.content.tostring()); objcmd.parameters.addwithvalue("", textbox3.text); // execute command objcmd.executenonquery(); } } }
i getting error as:
error [42000] [mysql][odbc 3.51 driver][mysqld-5.1.51-community]you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'order,orderdate) values ('04050040272009',' &' @ line 1
the datatype fields in table temp_save are:
fil_no-->int(15)( store 15 digit number) order-->longtext(to store contents htmleditor(ajax control)) orderdate-->date(to store date)
please me resolve error.
order reserved word. complete list of reserved words, please review this document.
you can wrap in back-ticks i.e. (on keyboard tick under ~ key)
insert temp_save (fil_no,`order`,orderdate)....
Comments
Post a Comment