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

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -