c# - Data type mismatch on write, reading works fine -


in asp.net webforms project .net 3.5 data transferred access database. site runs on iis 6 on windows 2003 (english cersion).

in aspx file accessdatasource used read , write data. reading data works fine, writing dates fails. writing works, if date provided mm-dd-yyyy, dd.mm.yyyy not work. if date provided dd.mm.yyy error:

system.data.oledb.oledbexception: data type mismatch in criteria expression. 

an code example leading error:

accessdatasource myads = new accessdatasource("~/app_data/mydb.mdb", ""); myads.insertcommand =     "insert [table1] " +     "([value], [date]) values ('data', datevalue('" + datetime.now.tostring("dd.mm.yyyy") + "'))"; myads.insert(); 

the regional , language settings set german , therefore correct date format. in database date , time stored in datetime field.

what have cofigure correct this, without changing hundrets of pages of legacy code?

change

datetime.now.tostring("yyyy-mm-dd") 

if trying insert currentdatetime can like

 "insert [table1] " + "([value], [date]) values ('data', now())"; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -