Click here to Skip to main content
15,916,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds,

I have a registration form in my project, when user open this page a code number must be generated automatically in textbox.
so we can understand, this is the code for this user.

The code must be generated as (UserDepartment-001)
Example
===========
UserIT-001
UserIT-002
UserIT-003

The code must be automatically generated in Textbox(TxtGeneratedCode) when the page loads.

Please can you help me how to do this.

Thanks in advance.
Posted

No. Don't do it. Don't even try.

How many users do you think will be trying to register at the same time? One, or more than one?

If it's more than one - and it will be in the real world - and you "pre-generate" the user code, then all the current users will be given teh save value.

Only ever generate user ids and so forth when you insert them to the system: because only then can you be sure exactly what value they can have - think how much trouble you could get into with more than one person with the same value?

Then, exactly how to generate the code will depend on how you are storing it...
 
Share this answer
 
Refer this : Custom Auto-Generated Sequences with SQL Server[^][I assume you are using SQL Server].

I am agree with what OG stated above and using this link you should generate the number at the time of insertion of record.
 
Share this answer
 

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