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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -