Employee ID Autogeneration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silpa
    New Member
    • May 2007
    • 20

    Employee ID Autogeneration

    Hi,
    i have a windows based aplication in that A field named EmployeeID (textbox) is there.Its value should be autogenerated from the sql server database.
    the condition is that
    1) The ID should start with A01,A02,....... .A99
    After A99, the next ID should be B01,B02.......s o on.


    pls give me any suggestion and if possible give me a sample code for reference with records.


    Thanks and regards,
    Silpa
  • prabunewindia
    New Member
    • Mar 2007
    • 199

    #2
    wait my friend,
    i am having some work now.
    i will give solution after 2 hrs
    Prabu

    Originally posted by silpa
    Hi,
    i have a windows based aplication in that A field named EmployeeID (textbox) is there.Its value should be autogenerated from the sql server database.
    the condition is that
    1) The ID should start with A01,A02,....... .A99
    After A99, the next ID should be B01,B02.......s o on.


    pls give me any suggestion and if possible give me a sample code for reference with records.


    Thanks and regards,
    Silpa

    Comment

    • prabunewindia
      New Member
      • Mar 2007
      • 199

      #3
      hai friend,

      try with this code

      Code:
      // get the prevID here from table
                  string prev=///from table
                  string newID="";
                  char ch = (prev.ToCharArray())[0];
                  int no=Convert .ToInt32 (prev .Substring(1));
                  if(no==99)
                  {
                      ch++;
                  newID =ch.ToString()+"00";//or "01" if u don't need 00
                  }
                  else if (no<9)
                  {
                      no++;
                      newID =ch.ToString ()+"0"+no.ToString ();
                  }
                  else 
                  {
                      no++;
                      newID =ch.ToString ()+no.ToString ();
                  }
      
                 TextBoxEmpID.Text=newID;
      if the table has no row(no employee addded) then directly print A00 or A01

      Prabu

      Originally posted by silpa
      Hi,
      i have a windows based aplication in that A field named EmployeeID (textbox) is there.Its value should be autogenerated from the sql server database.
      the condition is that
      1) The ID should start with A01,A02,....... .A99
      After A99, the next ID should be B01,B02.......s o on.


      pls give me any suggestion and if possible give me a sample code for reference with records.


      Thanks and regards,
      Silpa

      Comment

      • silpa
        New Member
        • May 2007
        • 20

        #4
        Hi,
        Thankyou very much for helping me by sending the code.

        Silpa




        Originally posted by prabunewindia
        hai friend,

        try with this code

        Code:
        // get the prevID here from table
                    string prev=///from table
                    string newID="";
                    char ch = (prev.ToCharArray())[0];
                    int no=Convert .ToInt32 (prev .Substring(1));
                    if(no==99)
                    {
                        ch++;
                    newID =ch.ToString()+"00";//or "01" if u don't need 00
                    }
                    else if (no<9)
                    {
                        no++;
                        newID =ch.ToString ()+"0"+no.ToString ();
                    }
                    else 
                    {
                        no++;
                        newID =ch.ToString ()+no.ToString ();
                    }
        
                   TextBoxEmpID.Text=newID;
        if the table has no row(no employee addded) then directly print A00 or A01

        Prabu

        Comment

        Working...