Hi,
I getting a error while try to fetch a ID +1 number(int) into a textbox.
This is the sql server query: -
SELECT MAX(SlabID)+1 FROM INVSTSLAB
The error is below:-
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Bineesh ViswanathRank #1,680 · 907 reputationPosted Nov 12, 2014, 12:25 AM EST
it was the mistake from sql query.
Corrected SQl Query:-
SELECT max(cast(SlabID as int)) + 1 as SlabID
Corrcted C# code :-
txtSlabID.Text = rdr["SlabID"].ToString();
Abhay ShankerRank #375 · 6.7K reputationPosted Nov 12, 2014, 12:50 AM EST
So first check query its returning max+1 value
Also Modify the code as below
while(rdr.Read())
{
txtSlabID.Text = rdr["SlabID"].ToString();
}
rdr.Close();
cn.Close();