Hi
I have the following bit of code
string test0001 = "Select Max(activity_order) from roomactivitylk";
int max;
SqlCommand cmd15 = new SqlCommand();
cmd15.Connection = con;
cmd15.CommandText = test0001;
max = (int)cmd15.ExecuteScalar();
max = max + 1;
what it does is add 1 to the value max which is taken from the database
however it seems to be set to 0 as everytime it brings back 0 even though the next incrment value should be 2
any suggestions?
cheerts
Hi
I am not sure which parts of the code is in a loop. But i guess, the "int max" declaration should be outside of the loop (if it is already not).
Hope this helps.
VJ
|||My guess is u want to perform autoincrement . If i m right i think u may not get it because when there r no records exist check the return value.u may get null if u get null make it as 1 or increment with the max value. Plz reply to me am i rt or wrong
Thank u
Baba
Please remember to click "Mark as Answer" on this post if it helped you.
Hi
thanks for the replys manmaged to sort it
this is the soltuion
string maxquery = "Select Max(activity_order) from roomactivitylk ";
//cmd14.ExecuteScalar();int max;
SqlCommand cmd15 = new SqlCommand();
//SqlCommand cmd15 = new SqlCommand(test0001, con);
cmd15.Connection = con;
cmd15.CommandText = maxquery;
max = (int)cmd15.ExecuteNonQuery();
max = max + 2;
++max;
max++;ps yes i was tring to increment:-)
cheers!!
No comments:
Post a Comment