Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to generate unique id for Student while registration with combination of three values
1-first two letters of the school name ex:(WiseTime)
2-Autogenerated Number ex:(1)
3-year of registration ex:(2013)

//i want that unique ID as like below
wi12013 - first student
wi22013 - second student
-
-
//like that i want to generate the id for student.

//is it possible

i am having only one value that is school name.rest of the two values Auto generated number,current year

//this was my code sir in the @student_id i want to pass the value with aboue criteria

SqlCommand cmdAdmission = DBManager.DataAccess.command();
cmdAdmission.Parameters.Add(new SqlParameter("@option", SqlDbType.VarChar, 50));
cmdAdmission.Parameters["@option"].Value = "SubmitAdmission";

cmdAdmission.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,20));
cmdAdmission.Parameters["@Student_id"].Value = ?????

cmdAdmission.Parameters.Add(new SqlParameter("@School_Name", SqlDbType.NVarChar,100));
cmdAdmission.Parameters["@School_Name"].Value = Session["SchoolName"].ToString();

cmdAdmission.Parameters.Add(new SqlParameter("@Date_of_birth",SqlDbType.VarChar,20));
cmdAdmission.Parameters["@Date_of_birth"].Value = DOB;

string sqlquery = "SchoolProc";
DBManager.DataAccess.executeQuery(sqlquery);
if (DBManager.DataAccess.i > 0)
{
string strScript = "<script>";
strScript += "alert('Child Details Taken Successfully');";
strScript += "</script>";
strScript += "window.location='welcome.aspx';";
Page.RegisterClientScriptBlock("strScript", strScript);
DBManager.DataAccess.EmptyTextBoxes(this.Page);
}
Posted
Updated 19-Feb-13 0:12am
v5

Yes, it's possible. Exactly how you would do it will depend on what kind of systems you are interfacing, and where you are storing the info, and where you want to generate it.

However, I would suggest that you re-think your scheme a little: firstly work out how many students you can get in a year and allocate a suitable number of digits as a fixed length. So if you can expect 250 students in a year, allow three digits and pad with zeros, if you can expect 950 than allow four digits and again pad with zeros.

Secondly, change the order slightly: swap the year and student number.

ssYYYYnnnn
where
  ss    is the school,
  YYYY  is the year,
  nnnn  is the student number
Is a lot easier to search for and sort than dealing with variable length student numbers in the middle.


"sir i am coding through front end that means through asp.net...."


I see from you modifications to the question that you are using SQL - OK, here is how I would do it.

SQL Server has the facility to generate automatic number fields: it can add a value (one for example) to an integer field each time you insert a record. If you use this, you can preset it to the year and a start number each academic year:
20120001 for the year 2012-2013
20130001 for the year 2013-2014
20140001 for the year 2014-2015
And it will generate the number for you.
If you set up two fields in your table:
SchoolId   CHAR(2)
StudentID  INT, Identity
You can return the whole code by:
SQL
SELECT SchoolId + CAST(StudentId AS varChar(8)) AS ID FROM myTable
At the start of registrations for the new academic year, you reset the starting value of the identity field to the new year value, and let SQL handle all the rest! The beauty of this is that it lets SQL do the work, so this will always work in a multiuser environment - so if you have five clerks entering new student data, they can't end up with two students with the same number!
 
Share this answer
 
v2
Comments
ntitish 19-Feb-13 4:58am    
then how to get the current year sir...and number of the student.
OriginalGriff 19-Feb-13 5:43am    
As I say, it depends on what you are trying to use. If it;s an SQL database, then there are a number of solutions, if it's an XML file there are differernt methods. Single user methods will also be very different from multiuser solutions. The year is easy, regardless of wht you do - but how you get it may also change depending on what you are doing!

So tell us what you want to do in enough detail! :laugh:
ntitish 19-Feb-13 6:06am    
sir u not getting my problem i think so. it was my fault only. i am unable to explain my problem.
OriginalGriff 19-Feb-13 6:16am    
Try teh suggestion I gave a little while ago - it's easier than you think, and it will do what you want. Trust me on this...
ntitish 19-Feb-13 6:20am    
I want that id with school_name also sir, for example wisetime is my school name means my ID for current year should be in this format
WI20130001
 
Share this answer
 
SQL
select 'QA /' + substring(convert(varchar(11),getdate(),102),3,2) +
substring(convert(varchar(11),getdate(),100),1,3) + '/' +
ltrim(substring(convert(varchar(11),getdate(),100),5,2))

output :--
QA/Curentyear and month/currentDate
 
Share this answer
 
Use this Code for Auto Generate...

C#
public void autogencode()
    {
        con.Open();
        int newid = 1;
        string strnewid = " ";
        cmd = new SqlCommand("select max(ProjectNo) from TblNewProject ", con);
        object obj = cmd.ExecuteScalar();
        if (obj.ToString() != "")
        {
            newid = Convert.ToInt32(obj.ToString()) + 1;
            strnewid = newid.ToString();
            strnewid = strnewid.PadLeft(3, '0');
            autoid = "CAS" +"/"+ (txtprojectcode.Text).ToUpper() +"/"+ strnewid;
            auto = newid;
        }
        else
        {
            autoid = "CAS" +"/"+ (txtprojectcode.Text).ToUpper() +"/"+ "001";
            auto = 1;
        }
        con.Close();
    }
 
Share this answer
 
Comments
ntitish 19-Feb-13 4:51am    
how to get the current year sir....

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