Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how can i make the output like

ABC0001
ABC0002
ABC0003

that will automatically generate that output.. THANKS!
Posted
Comments
Zoltán Zörgő 12-Aug-13 15:03pm    
The question is: what comes after ABC9999? Everything else depend on this.
If ABD0000, than you need some sort of "number system", if there is nothing after that, you will simply need to use output formatting - depending on the output method.

is this want you wanted?

C#
static List<string> GenID(int n)
        {
            string prefix = "ABC";
            char zero = '0';
            List<string> idList = new List<string>();
            string next = "";
            int nzeros = 0;
            if (n > 0)
            {
                for (int k = 1; k <= n; k++)
                {
                    next = prefix;
                    if (k <= 9) nzeros = 3;
                    else if (k <= 99) nzeros = 2;
                    else if (k <= 999) nzeros = 1;
                    else nzeros = 0;
                    for (int j = 0; j < nzeros; j++)
                    {
                        next += zero.ToString();
                    }
                    next += k.ToString();
                    idList.Add(next);
                }
            }
            return idList;
        }
</string></string></string>
 
Share this answer
 
Comments
Member 10163198 12-Aug-13 0:19am    
i am using vb.net and sql
Look into SQL "composite primary keys". You split your ID into multiple columns. The numeric part, which the database should increment, NOT YOUR CODE!, will be seperate from the alpha part of your key.
 
Share this answer
 
Comments
Member 10163198 13-Aug-13 4:21am    
but how..
Dave Kreskowiak 13-Aug-13 7:29am    
I already told you what to Google for. That's how you find out "how".

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