1
Answer

how to Generate a unique ID based on input

Photo of Mustaq Khan

Mustaq Khan

12y
1.5k
1
                         I want to generate a unique ID based on the input in Windows form...Something like this COM244100...where 1st 3 characters are the Event Name , next 2 digit is the date , next digit is the month , and the remaining are the Id...!!
                        I am using Ms access as a database....Please Help
 

Answers (1)

0
Photo of Vulpes
NA 96k 2.6m 12y
Well, you could generate such an ID with code such as this:

       string evt = "COM";
       int id = 100;
       DateTime dt = DateTime.Now;
       string uniqueID = String.Format("{0}{1:D2}{2:D2}{3}", evt, dt.Day, dt.Month, id);

Notice that you'll need to allow 2 digits for the month if October, November and December are to be catered for.

How unique this is going to be will depend, of course, on how unique the 'id' component is relative to the other components.