c# - How to fix ExecuteNonQuery error -


an exception thrown on executenonquery, how can fix it?

string sqlquery = "insert transaction(id,item_name,quantity,price,t_date) values (?,?,?,?,?)"; using (oledbconnection conn = new oledbconnection("provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\\kcdb.accdb")) using (oledbcommand cmd = new oledbcommand(sqlquery, conn)) {     conn.open();     cmd.parameters.addwithvalue("@id", id);     cmd.parameters.addwithvalue("@item_name", item.tostring());     cmd.parameters.addwithvalue("@quantity", quantity);     cmd.parameters.addwithvalue("@price", price);     cmd.parameters.addwithvalue("@t_date", dt.tostring());     cmd.executenonquery(); } 

for guiding you, need exception , because there different reasons of failure. can see in code there casts in assigning value parameters, when parameter of datetime type should pass datetime value not string. think should change cmd.parameters.addwithvalue("@t_date", dt.tostring()); cmd.parameters.addwithvalue("@t_date", dt);


Comments

Popular posts from this blog

Change the color of an oval at click in Java AWT -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -