How to get Max id From Database using c#? -
cmd = new oledbcommand("select max(substr(tr_refno,9,6))as refid echallan dept='" +tmpdept.tostring() + "' , substr(tr_refno,5,2) ='" + tmpmonth + "'", con); maxid = convert.toint16( cmd.executescalar());
error= invalidcastexception unhandled user code
before converting check nullity:
var value = cmd.executescalar(); int maxi; if(value !=null) maxid = convert.toint32(value); else //......................
Comments
Post a Comment