如何制作可以生成ABC00001的ID [英] How to make a ID that can generate ABC00001

查看:75
本文介绍了如何制作可以生成ABC00001的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能输出像



ABC0001

ABC0002

ABC0003



将自动生成该输出..谢谢!

how can i make the output like

ABC0001
ABC0002
ABC0003

that will automatically generate that output.. THANKS!

推荐答案

这是你想要的吗?



is this want you wanted?

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>


查看SQL复合主键。您将ID拆分为多个列。数据库应该增加的数字部分,而不是你的代码!,将与密钥的alpha部分分开。
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.


这篇关于如何制作可以生成ABC00001的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆