ID Auto Generation

We need to auto generate ID's say Employee ID, Student ID etc , in order to avoid the duplication.

The below piece of code will give you a idea about ID Auto generation.
Here have to select the max value of the id and have to increment it accordingly.




int iJobid = 0;
SqlConnection sqlCon = new SqlConnection(""Database=Master;Server=in123;User ID=sa;Password=sa123;");
sqlCon.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlCon;
sqlCmd.CommandText = "Select Max(EmpID) from EmployeeDetails";
iJobid = (int) sqlCmd.ExecuteScalar();
sqlCon.Close();
if (iJobid > 0)
iJobid = iJobid + 1;
else
iJobid = 1;
txtEmpID.Text = iJobid.ToString();


Comments

Author: Atul Vishwakarma19 May 2009 Member Level: Bronze   Points : 1

This code is to simple...

Can you give the code increment like

ABCA,ABCB,..., ABCZ,ABDA,..ABDZ,..., ABEA,...

Bye...

Guest Author: deepa07 Jun 2012

Code for autogeneration

Guest Author: Anil20 Dec 2012

using char variable replacin int for ABC ,,,,,;)



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: