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
Post a Comment