Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi,
i want to generate 13 digits unique random account number for my project this number includes branch code, area code and all should be stored in database sql 2008 and code for this should be in c# please help me for this



thanks in advance
Posted
Updated 30-Mar-11 21:25pm
v2
Comments
Eduard Keilholz 31-Mar-11 3:18am    
What do you have right now? What part isn't working? Or do you really expect us to write the entire code for you?

Eduard
[no name] 31-Mar-11 3:30am    
Hey, as your requirement, you need Branch code, area code in your unique code. First of all this should not be done using random no. since you always need same branch and area cone.
I can give you solution but first you re-think.

1 solution

What is the problem? We can't give you code, we don't know the branch or area code formats, so we have no idea about the rest of it. But Random is easy:

private Random rand = new Random(); // Class level random number generator
...
int randomNumber = rand.Next(1000000);           // Generate a random number between 0 and 999999
string randomCode = randomNumber.ToString("D6"); // Convert it to six digits, 0 padded.
Then combine with your branch and area codes, and see if it is in the db already!
You might want to add a check digit or similar to make it harder for human error to slip in...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-Mar-11 14:32pm    
You're right, no problem. A 5.
--SA

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