c# mysqlcommnand insert into mysql database -


i have program insert list of field database. when use own computer insert datetime field looks completing fine. however, when insert using windows 7 chinese edition, field become 0000-00-00 00:00:00 command

mysqlcommand mycommand4 = new mysqlcommand("insert orderrecords_table values('" + orderidlabel.text + "','" + customercode + "','" + customer + "','" + telcombobox.text + "','" + licensecombobox.text + "','" +                       drivercombobox.text + "','" + addresscombobox.text + "','" + locationtypecombobox.text + "','" + pickupcombobox.text + "','" + customertypelabel.text + "','" +                       convert.todecimal(totalpricelabel.text) + "','" + status + "','" + note + "','" + sandreceiptno + "','" + createtiming + "','" + convert.todatetime(datetime.now.tostring("yyyy-mm-dd hh:mm:ss")) + "')", myconnection); mycommand4.executenonquery(); 

i know looks bit messy, part says str_to_date('" + datetime.now.tostring("yyyy-mm-dd hh:mm:ss") + "','%y/%m/%d /%h/%m/%s'))" part insert current datetime. works fine when use english version of windows, whenever use chinese edition, isnert 0000-00-00 00:00:00 instead of actual time, have tried change format showing dates in control panel, still having same problem.

anyone knows problem ?

thanks

edited code

var sql = "insert orderrecords_table values(@orderid, @customercode, @customer, @phonenumber, @license, @driver, @address, @type, @pickuplocation, @paymentmethod, @totalprice, @status, @notes, @sandreceiptno,@createtime, @edittime)";              using (var mycommand4 = new mysqlcommand(sql, myconnection))             {                                mycommand4.parameters.addwithvalue("@orderid", mysqldbtype.varchar).value = orderidlabel.text;                 mycommand4.parameters.addwithvalue("@customercode", mysqldbtype.varchar).value =  customercode;                 mycommand4.parameters.addwithvalue("@customer",mysqldbtype.varchar).value = customer;                 mycommand4.parameters.addwithvalue("@phonenumber", mysqldbtype.varchar).value =telcombobox.text;                 mycommand4.parameters.addwithvalue("@license", mysqldbtype.varchar).value = licensecombobox.text;                 mycommand4.parameters.addwithvalue("@driver", mysqldbtype.varchar).value = drivercombobox.text;                 mycommand4.parameters.addwithvalue("@address", mysqldbtype.varchar).value = addresscombobox.text;                 mycommand4.parameters.addwithvalue("@type", mysqldbtype.varchar).value = locationtypecombobox.text;                 mycommand4.parameters.addwithvalue("@pickuplocation", mysqldbtype.varchar).value = pickupcombobox.text;                 mycommand4.parameters.addwithvalue("@paymentmethod", mysqldbtype.varchar).value = customertypelabel.text;                 mycommand4.parameters.addwithvalue("@totalprice", mysqldbtype.decimal).value = convert.todecimal(totalpricelabel.text);                 mycommand4.parameters.addwithvalue("@status", mysqldbtype.varchar).value = status;                 mycommand4.parameters.addwithvalue("@notes",  mysqldbtype.varchar).value =status;                 mycommand4.parameters.addwithvalue("@sandreceiptno", mysqldbtype.varchar).value = sandreceiptno;                 mycommand4.parameters.addwithvalue("@createtiming", mysqldbtype.datetime).value = createtiming;                 mycommand4.parameters.addwithvalue("@edittime", mysqldbtype.datetime).value = datetime.now;                 mycommand4.executenonquery(); 

its saying have invalid input, have checked few times fields asigned correct type.. . don't know happening

i've rewritten code more standardized implementation (with best practices). note i've pulled query out separate variable let code , query become more readable.

var sql = "insert orderrecords_table values " +           "(@orderid,                            " +           " @customercode,                       " +           " @customer,                           " +           " @telephone,                          " +           " @license,                            " +           " @driver,                             " +           " @address                             " +           " @locationtype,                       " +           " @pickup,                             " +           " @customertype,                       " +           " @totalprice,                         " +           " @status,                             " +           " @note,                               " +           " @sandreceiptno,                      " +           " @createtiming,                       " +           " @currenttime)                        ";  using (var mycommand4 = new mysqlcomm## heading ##and(sql, connection)) {    mycommand4.parameters.addwithvalue("@orderid", orderidlabel.text) ;    mycommand4.parameters.addwithvalue("@customercode", customercode);    mycommand4.parameters.addwithvalue("@customer", customer);    mycommand4.parameters.addwithvalue("@telephone", telcombobox.text);    mycommand4.parameters.addwithvalue("@license", licensecombobox.text);    mycommand4.parameters.addwithvalue("@driver", drivercombobox.text);    mycommand4.parameters.addwithvalue("@address", addresscombobox.text);    mycommand4.parameters.addwithvalue("@locationtype", locationtypecombobox.text);    mycommand4.parameters.addwithvalue("@pickup", pickupcombobox.text);    mycommand4.parameters.addwithvalue("@customertype", customertypelabel.text);    mycommand4.parameters.addwithvalue("@totalprice", convert.todecimal(totalpricelabel.text));    mycommand4.parameters.addwithvalue("@status", status);    mycommand4.parameters.addwithvalue("@note", status);    mycommand4.parameters.addwithvalue("@sandreceiptno", sandreceiptno);    mycommand4.parameters.addwithvalue("@createtiming", createtiming);    mycommand4.parameters.addwithvalue("@currenttime", datetime.now);     mycommand4.executenonquery(); } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -