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

Example
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.

Regards,
D Patel
LVL 7
D PatelD Patel, Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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?
0
D PatelD Patel, Software EngineerAuthor Commented:
Yes in MySQL table
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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.
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

D PatelD Patel, Software EngineerAuthor Commented:
Can you please brief about it more Ryan Chong?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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:

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

DECLARE newKey VARCHAR(255);
DECLARE isUnique BIT;

SET isUnique = 0;

 loop_label:  LOOP
 
	 SET newKey = CONCAT(SUBSTRING('ABCDEFGHIJKLMNOPQRSTUVWXYZ', RAND()*25+1, 1) , UPPER(LEFT(UUID(), keylength -1)));
	 SELECT COUNT(*) INTO isUnique FROM yourExisting_Table WHERE uniqueKey = newKey;

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

DELIMITER ;

Open in new window


then you can use this generated key for data insertion.
0

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.
0
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
ASP.NET

From novice to tech pro — start learning today.