Wrong date after update C# & Sql server 2008 -


i'm developing c# windows mobile app:

in form, read (since mi mobile) records on server database (my pc) -sql server 2008- , these records stored in mobile db -.sdf file- after i'll calcs them, , after calcs, records return server database (my pc again) -sql server 2008-

this code read records , save them on mobile:

sql0 = new sqlcommand("select * acct fasm = '" + uss+ "'  ", conn); //"uss" user //code lines //... //more code lines string numia, numipo, numctivo;  sqlcommand sqla = new sqlcommand("select * acmct frasm = '" + usuario + "' ", conn); qla.executenonquery(); sqldataadapter cba = new sqldataadapter(sqla); datatable dta = new datatable(); cba.fill(dta); foreach (datarow dra in dta.rows) {     numia = dra["numia"].tostring();     numipo = dra["numipo"].tostring();     numctivo = dra["numctivo"].tostring();     //and more code lines     fdqis = dra["fdqis"].tostring(); //<<<< here starts problem: fdqis gets "02/09/00 0:00:00"     stringbuilder sbquery0 = new stringbuilder();     sqlcecommand cmd00 = new sqlcecommand();     sbquery0.append("insert acmct (numia, numipo, numctivo... )values('" + numia + "','" + numipo + "','" + numctivo + "'... )");     cmd00.commandtext = sbquery0.tostring();     cmd00.connection = connd;     cmd00.executenonquery();     cmd00.dispose();     if (fdqis == "")     {     //code lines     }     else     {     datetimepicker1.value = datetime.parse(dra["fdqis"].tostring());     stringbuilder sbquery1 = new stringbuilder();     sqlcecommand cmd1k = new sqlcecommand();      sbquery1.append("update acmct set fdqis = " + datetimepicker1.value.tostring("yyyy/mm/dd") + " numia = '" + numia + "' ... ... ");     cmd1k.commandtext = sbquery1.tostring();     cmd1k.connection = connd;     cmd1k.executenonquery();     cmd1k.dispose();     } } 

i thought woring right, problem is: read server database value of date "02/09/00 0:00:00", after update saved "09/02/00 0:00:00" , when i'm trying show on screen, shows: "22/04/00 0:00:00". being sincere, don't understand why happens.

this code show data on screen:

conn.connectionstring = ("data source =" + (system.io.path.getdirectoryname(system.reflection.assembly.getexecutingassembly().getname().codebase)) + "\\database.sdf;password=****;persist security info=false;");             conn.open();             sqlcecommand sql = new sqlcecommand("select * acmct acmct.numctivo = '" + oc.text + "' , acmct.numia = '" + cia.text + "' , acmct.numipo = '" + tipo.text + "' , acmct.sunumct = '" + subnum.text + "'", conn);             sql.executenonquery();             sqlcedataadapter cb = new sqlcedataadapter(sql);             datatable dt = new datatable();             cb.fill(dt);             foreach (datarow dr in dt.rows)             {                 manntt ma = new manntt();                  ma.txtcia.text = dr["numia"].tostring();                 ma.txtipo.text = dr["numipo"].tostring();                 ma.txtsubu.text = dr["subumct"].tostring();                 ma.txtfadqfis.text = dr["fdqis"].tostring();//here value of txtfadqfis "22/04/00 0:00:00"                 ma.show();             } 

am doing insert/update/delete wrong?

any idea do?

i had similar problem weeks ago! believed inserts , updates, deletes wrong! weren't...

the solution simple:

try this:

else     {     datetimepicker1.value = datetime.parse(dra["fdqis"].tostring());     stringbuilder sbquery1 = new stringbuilder();     sqlcecommand cmd1k = new sqlcecommand();  sbquery1.append("update acmct set fdqis = '" + datetimepicker1.value.tostring("yyyy/mm/dd") + "' numia = '" + numia + "' ... ... ");  //////////// note: use '' @ beginning , @ end of date  cmd1k.commandtext = sbquery1.tostring(); cmd1k.connection = connd; cmd1k.executenonquery(); cmd1k.dispose(); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -