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.
Loading
SUNIL GUTTAPosted Sep 3, 2013, 2:24 PM
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
Saber ShaikhPosted Sep 3, 2013, 2:08 PM