Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i am genrating autonumer using code
C#
random rn=new random, cmd.Parameters.Add(new SqlParameter("@fecultyregno",rn.Next(9999)));

i want insert value in database in this form
faculty/random number how i can do

and my sql query:::

SQL
Insert Into addfaculty(fecultyregno,post,title,firstname,middlename,lastname,dob,gender,houseno,street,correspondanceadd,pgdegree,pguniversity,pgstartingyear,pgendyear,pgspecilization,pgmarks,pgdivision,ugdegree,uguniversity,ugstartingyear,ugfinishyear,ugspecil,ugmarks,ugdiv,otherdegree,otheruniversity,otherstartingyear,otherfinishyear,otherspecil,othermarks,otherdiv,highunivert,highfinishyer,highspecilzation,highmarks,highdiv,interunivert,interfinishyear,interspecilization,intermarks,interdiv,firstinstitution,firstdesignation,firstfrom,firstto,firstjobrole,secondinstitution,seconddesignation,secondfrom,secodto,secodjobrole,nationality,city,imagepath,imgname,facdate)
values
(@fecultyregno,@post,@title,@firstname,@middlename,@lastname,@dob,@gender,@houseno,@street,@correspondanceadd,@pgdegree,@pguniversity,@pgstartingyear,@pgendyear,@pgspecilization,@pgmarks,@pgdivision,@ugdegree,@uguniversity,@ugstartingyear,@ugfinishyear,@ugspecil,@ugmarks,@ugdiv,@otherdegree,@otheruniversity,@otherstartingyear,@otherfinishyear,@otherspecil,@othermarks,@otherdiv,@highunivert,@highfinishyer,@highspecilzation,@highmarks,@highdiv,@interunivert,@interfinishyear,@interspecilization,@intermarks,@interdiv,@firstinstitution,@firstdesignation,@firstfrom,@firstto,@firstjobrole,@secondinstitution,@seconddesignation,@secondfrom,@secodto,@secodjobrole,@nationality,@city,@imagepath,@imgname,GETDATE())
Posted
Updated 13-Feb-14 20:07pm
v2
Comments
thatraja 14-Feb-14 3:06am    
Hereafter don't repost questions. Always update existing question with details(which members asked you). I have deleted your previous question as it's a duplicate of this question.

1 solution

Seriously?
What happens when the random number generator duplicated a number?

And with a small phase space like that, the odds are 50-50 after only 5000 entries, so it's going to happen pretty often.

Instead, make the SQL column an Identity column, and let SQL handle the auto numbering.
 
Share this answer
 
Comments
thatraja 14-Feb-14 2:45am    
Agree, 5!

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