c# - data type mismatch in criteria expression error -
con.close(); cmd = new oledbcommand(@"insert tbl_alltransactions values (@transdate, @transtype, @transdesc, @transamount, @transcategory, @transfreq, @transpayvia, @transpaid, @transtopay, @transnextpay, @transstatus, @transmonth, @transweek, @transyear, @c_name ,@transmode)", con); cmd.parameters.addwithvalue("@transdate", firstpay.toshortdatestring()); cmd.parameters.addwithvalue("@transtype", cbtranstype.text); cmd.parameters.addwithvalue("@transdesc", txtdesc.text); cmd.parameters.addwithvalue("@transamount", txtmoney.text); cmd.parameters.addwithvalue("@transcategory", cbcategory.text); cmd.parameters.addwithvalue("@transfreq", cbfreq.text); cmd.parameters.addwithvalue("@transpayvia", cbpay.text); cmd.parameters.addwithvalue("@transpaid", i); cmd.parameters.addwithvalue("@transtopay", txtpayments.text); if (i <= (totpayments - 1)) { cmd.parameters.addwithvalue("@transnextpay", nextpay.toshortdatestring()); } if (i == totpayments) { cmd.parameters.addwithvalue("@transnextpay", firstpay.toshortdatestring()); } if (i <= (totpayments - 1)) { transstatus = "uncleared"; cmd.parameters.addwithvalue("@transstatus", transstatus); } if (i == totpayments) { transstatus = "cleared"; cmd.parameters.addwithvalue("@transstatus", transstatus); } cmd.parameters.addwithvalue("@transmonth", whichmonth); cmd.parameters.addwithvalue("@transweek", whichweek); cmd.parameters.addwithvalue("@transyear", whichyear); cmd.parameters.addwithvalue("@c_name", cname); transmode = cbduration.text; cmd.parameters.addwithvalue("@transmode", transmode); con.open(); int j = convert.toint32(cmd.executenonquery()); if (j == 1) { j = 0; // nextpay = firstpay = datetime.now; } con.close();
using addwithvalue
means datatype parameter value determined value itself. so, example, datatype of parameter @transdate
string, not date because use toshortdatestring()
conversion. of course requires field updated parameter string not date.
you need check, if every parameter goes update compatible field type, example parameter @transamount
. database field string? pass text property of textbox, should string.
there potential problem. should sure parameters @transnextday
, @transstatus
added collection. current code present possibility these parameters not added (i > totpayments)
Comments
Post a Comment