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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -