winforms C# using sql server 2008 -


private void fillcode() {     try     {         sqlconnection con = new sqlconnection("data source=anish;initial catalog=hm;integrated security=true");         con.open();         string s = "select max(customerid) id customerdetails";         sqlcommand cmd = new sqlcommand(s, con);         sqldatareader dr = cmd.executereader();         dr.read();         int = convert.toint16(dr["id"].tostring());         sid.text = (i + 1).tostring();         con.close();     }     catch (exception ex)     {         messagebox.show(ex.message);     } } 

i using code, there problem if there no data in table not accept. want use if no data present should take customerid 1

it null of there no rows can:

"select isnull(max(customerid), 1) id customerdetails" 

you should @ executescalar designed singe result.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -