Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to increment the Employee ID Like this
EMP001
EMP002
EMP003
Posted
Comments
Prerak Patel 25-Aug-11 2:42am    
So what is the problem? Did you try anything?

may be this code help you.....
string empID = "";
      for (int i = 0; i < 1000; i++)
      {

          if (i.ToString().Length == 1)
          {
              empID = "EMP00" + i.ToString();
          }
          else if (i.ToString().Length == 2)
          {
              empID = "EMP0" + i.ToString();
          }
          else if (i.ToString().Length == 3)
          {
              empID = "EMP" + i.ToString();
          }
          listBox1.Items.Add(empID);
      }
 
Share this answer
 
Comments
CPallini 25-Aug-11 3:00am    
There are more concise ways to do that.
Timberbird 25-Aug-11 3:01am    
No, I doubt it would. This code just generates a lot of strings and puts them in a control. Besides, it's... well, the LEAST I can say it's horribly non-optimal.
You can do it this way: Create a stored procedure to count the number of the records on your table. Return that value to the C# application. From there, you can add 1 to the returned value and concatenate it to the EMP.
 
Share this answer
 
Comments
kornakar 25-Aug-11 2:56am    
This is not good: what if a record is deleted? Then the next number will be a one already used. The EmployerID must be kept in another table in order to make it unique.

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