c# - Problems by inserting values from textboxes -
i'm trying insert current date database , allways message(when press button on form save access database), data type incorect in conditional expression. code:
string constring = "provider=microsoft.jet.oledb.4.0;" + "data source=c:\\users\\simon\\desktop\\save.mdb"; oledbconnection empconnection = new oledbconnection(constring); string insertstatement = "insert obroki_save " + "([id_uporabnika],[id_zivila],[skupaj_kalorij]) " + "values (@id_uporabnika,@id_zivila,@skupaj_kalorij)"; oledbcommand insertcommand = new oledbcommand(insertstatement, empconnection); insertcommand.parameters.add("@id_uporabnika", oledbtype.char).value = users.idtextbox.text; insertcommand.parameters.add("@id_zivila", oledbtype.char).value = idtextbox.text; insertcommand.parameters.add("@skupaj_kalorij", oledbtype.char).value = textbox1.text; empconnection.open(); try { int count = insertcommand.executenonquery(); } catch (oledbexception ex) { messagebox.show(ex.message); } { empconnection.close(); textbox1.clear(); textbox2.clear(); textbox3.clear(); textbox4.clear(); textbox5.clear(); }
i have cut out date,( made access paste date ), still there same problem. first line ok? users.idtextbox.text? please !
try changing
insertcommand.parameters.add("@datum", oledbtype.char).value = datetime.now;
to
`insertcommand.parameters.add("@datum", oledbtype.char).value = datetime.now.tostring("dd mmm yyyy hh:mm");`
( or other acceptable date format)
Comments
Post a Comment