SqlCommand cmd = new SqlCommand("SELECT (MAX[Account_No] + 1) FROM addcustomer ", my);
cmd.ExecuteScalar();
int result = ((int)cmd.ExecuteScalar());
textBox1.Text =Convert.ToString( result);
i want to save the return value of this query in a integer like abve but nothing displayed on textbox.
Return value of sql querry
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Saber ShaikhRank #1,687 · 905 reputationPosted Sep 3, 2013, 10:08 AM EDT
SUNIL GUTTARank #1,832 · 810 reputationPosted Sep 3, 2013, 10:24 AM EDT
1. Connection string is not correct
2. If above one is working .. i doubt ur select statement i.e u quoting like MAX[account_no]+1 So Max function will get u last Account NO assuming ur PK as ACCOUNT_No ..
So by adding +1 to the coming account_no i.e which does not exist fetches u NULL values ..
Once check it .. Use Convert.toint32 which can handle null values better