如何在C#.NET Windows应用程序中自动递增ID [英] How to automatical increment an ID in c# .net windows application

查看:91
本文介绍了如何在C#.NET Windows应用程序中自动递增ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这样增加员工ID
EMP001
EMP002
EMP003

I want to increment the Employee ID Like this
EMP001
EMP002
EMP003

推荐答案

可能是这段代码可以帮助您.....
may be this code help you.....
string empID = "";
      for (int i = 0; i < 1000; i++)
      {

          if (i.ToString().Length == 1)
          {
              empID = "EMP00" + i.ToString();
          }
          else if (i.ToString().Length == 2)
          {
              empID = "EMP0" + i.ToString();
          }
          else if (i.ToString().Length == 3)
          {
              empID = "EMP" + i.ToString();
          }
          listBox1.Items.Add(empID);
      }


您可以按照以下方式进行操作:创建一个存储过程以对表中的记录数进行计数.将该值返回到C#应用程序.从那里,您可以将1添加到返回值并将其连接到EMP.
You can do it this way: Create a stored procedure to count the number of the records on your table. Return that value to the C# application. From there, you can add 1 to the returned value and concatenate it to the EMP.


这篇关于如何在C#.NET Windows应用程序中自动递增ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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