Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private string GenerateID()
      {


      }
      private void auto()
      {
          AdmissionNo.Text = "A-" + GenerateID();

      }


with prefix of A like below A-0001 A-0002 and so on .
Posted
Comments
Gihan Liyanage 4-Sep-14 6:56am    
Do you want to check the Database, for existing last Sequence number ?
Er Aslam Khan 4-Sep-14 6:57am    
no , before i generate random id 0-9 but now i want to generate sequential id like above so how implemet i

1 solution

All you have to do is have a private int:
C#
private int nextId = 1;
private void auto()
{
    lock(nextId)
       {
       AdmissionNo.Text = string.Format("A-{0:0000}", nextId++);
       }
}

You only need the lock if you are multithreading.
 
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