ASP.NET : Generate Unique Number of length 4 alphanumeric length where first character always start with alphabet

Hi EE,

I need help in generating the Unique Number of 4 character length.

Criteria is as follows :
  1. String will always start with alphabet
  2. Another 3 characters will be a combination of alphabets (A-Z) and digits (0-9)
  3. Once the number generated it could not be repeat

A001, A999, ZD01, DA9P, SXS8 etc...

I need to write a logic for the same in my ASP.NET (VB.NET) based web application.

Please provide a direction.

D Patel
D PatelD Patel, Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dorababu MSenior Software EngineerCommented:
Once the number generated it could not be repeat are you storing the generated number some where?
D PatelD Patel, Software EngineerAuthor Commented:
Yes in MySQL table
Ryan ChongSoftware Team LeadCommented:
thinking to have a stored procedure for data insertion and then build the logic for your field accordingly there?

then in your VB.NET program, you can call that stored procedure for data insertion.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

D PatelD Patel, Software EngineerAuthor Commented:
Can you please brief about it more Ryan Chong?
Ryan ChongSoftware Team LeadCommented:
well... not really have an example on hand, what i mean would be do "everything" at your database level, but if you saying to generate a unique key, you could simply use a Function instead:

USE `yourDB`$$
CREATE FUNCTION `getRandomKey`(keylength INT) RETURNS varchar(255) CHARSET utf8


SET isUnique = 0;

 loop_label:  LOOP
	 SELECT COUNT(*) INTO isUnique FROM yourExisting_Table WHERE uniqueKey = newKey;

	 IF  isUnique = 0 THEN 
		LEAVE  loop_label;
	 END  IF;
RETURN newKey;


Open in new window

then you can use this generated key for data insertion.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
D PatelD Patel, Software EngineerAuthor Commented:
Thanks for your support.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.