如何在注册时为特定学生创建唯一ID [英] How to Gnerate Unique ID for particular Student while registration

查看:104
本文介绍了如何在注册时为特定学生创建唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为学生生成唯一ID,同时注册三个值的组合

1 - 学校名称的前两个字母ex:(WiseTime)

2-自动生成数字ex:(1)

3年注册日期:(2013)



//我想要这个唯一ID下面

wi12013 - 第一个学生

wi22013 - 第二个学生

-

-

//喜欢我想为学生生成id。



//是否可能



i只有一个值是学校名称。两个值中的两个值自动生成的数字,当前年份



//这是我在@student_id中的代码先生我想要用aboue标准传递值



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]。值= DOB;



string sqlquery =SchoolProc;

DBManager.DataAccess.executeQuery(sqlquery);

if(DBManager.DataAccess.i> 0)

{

string strScript =< script>;

strScript + =alert(''儿童详情成功拍摄'' ');;

strScript + =< / script>;

strScript + =window.location =''welcome.aspx'';;

Page.RegisterClientScriptBlock(strScript,strScript);

DBManager.DataAccess.EmptyTextBoxes(this.Page);

}

解决方案

是的,这是可能的。具体如何,这将取决于您正在连接的系统类型,存储信息的位置,以及您想要生成它的位置。



但是,我建议你稍微重新考虑一下你的计划:首先计算出你一年可以得到多少学生,并分配一个合适的数字作为固定长度。因此,如果一年中可以预期250名学生,则允许三位数并使用零填充,如果您可以预期950而不是允许四位数并再次使用零填充。



其次,稍微改变订单:交换年份和学号。



 ssYYYYnnnn 
其中
ss是学校,
YYYY是年份,
nnnn是学生编号

搜索和排序比在中间处理可变长度的学生数字要容易得多。 />




先生,我通过前端编码,这意味着通过asp.net ....





我从你那里看到对你正在使用SQL的问题的修改 - 好的,我就是这样做的。



SQL Server具有生成自动数字字段的功能:每次插入记录时,它都可以向整数字段添加值(例如一个)。如果您使用此功能,您可以将其预设为每学年的年份和起始编号:

 2012  -  2012年20120001 
20130001 2013-2014两年2014 - 2014年
20140001

它将为您生成数字。

如果您在表中设置了两个字段:

 SchoolId CHAR(2)
StudentID INT,身份

您可以通过以下方式返回整个代码:

  SELECT  SchoolId + CAST(StudentId  AS   varChar  8 )) AS  ID  FROM  myTable 

在新学年开始注册时,您将身份字段的起始值重置为新年值,并让SQL处理所有其余内容!这样做的好处在于它可以让SQL完成工作,所以这将始终在多用户环境中工作 - 所以如果你有五个职员输入新的学生数据,他们最终不会有两个同等数量的学生! / blockquote>

检查我之前回答过的一些类似的主题:

用于插入操作的AutoGenerate Id [ ^ ]

我们如何在sql中的自动生成列中重新生成顺序用户ID。 [ ^ ]



..以及更多o n CP搜索 [ ^ ]

 选择 '  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 ))

输出 -
QA / Curentyear month / currentDate


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);
}

解决方案

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:

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!


Check some similar threads I have answered before:
AutoGenerate Id For Insert Operation[^]
How can we Re-Generated sequencial user id in autogenerated column in sql.[^]

..and more on CP Search[^]


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


这篇关于如何在注册时为特定学生创建唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆