c# - Unable to cast object of type -


i want maximum number

so did code

 public int autoincrement()     {         int no = 0;         odbccon.opencon();         sqlcommand cmd = new sqlcommand("select max (customercode) tblm_customer",odbccon.maincon);          sqldatareader dr = cmd.executereader();         if (dr.read())         {             if (!dr.isdbnull(0)) {                   no = convert.toint32(dr);              }          }         dr.close();         return no;      } 

but

no = convert.toint32(dr); 

says

unable cast object of type 'system.data.sqlclient.sqldatareader' type 'system.iconvertible'.

how can solve ? please tell me

you need specify index 0 datareader:

no = convert.toint32(dr[0]); 

Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -