Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I Want display next id in textbox.
If in my database table last id ID-0008 then in textbox it show ID-0009 when new user come for registration.
Please help ....
Posted
Comments
Sascha Lefèvre 7-Apr-15 0:51am    
And what have you tried so far?
[no name] 7-Apr-15 2:40am    
Ref this link : Click here.it's will help you.

 
Share this answer
 
Read the whole article and adopt Option 3 to auto generate custom ID.
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server[^]
 
Share this answer
 
v2
Solution for your Question.

Same Questions[^]

Suggestion:

This is the worst idea i think , Do not try to Display the next Id on the Textbox while on Page Load,If two or three user's open the same page at a time then what will happen?
Each have the Same next Id on the Text Box , So there is a possibility to Insert duplicate Id on Table.
 
Share this answer
 
v2
C#
public string MaxTranNo()
   {
       try
       {
           int TranNo = 0;

<pre>
       _SqlCon.Open();
       _SqlCmd.CommandText = &quot;SELECT MAX(TRAN_NO) FROM TABLE_NAME&quot;;
       da = new SqlDataAdapter(_SqlCmd);
       ds = new DataSet();
       da.Fill(ds);
       _SqlCon.Close();
       if (ds.Tables[0].Rows[0][0] != DBNull.Value)
       {
           TranNo = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
           TranNo = TranNo + 1;
       }
       else
       {
           TranNo = 1;
       }

       return TranNo.ToString();
   }
   catch (Exception ex)
   {
       throw ex;
   }
   finally
   {
       _SqlCon.Close();
   }


}

in return type you will get your value from the database
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900