如何将id自动增量到文本框中。 [英] how to get autoincrement of id to a textbox.

查看:159
本文介绍了如何将id自动增量到文本框中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用EMPID和Ename的应用程序如何自动生成Emp id,这意味着它应该自动将emp id显示到文本框。

解决方案

我假设您使用的是SQL DB ..



  //  定义一种方法 
public int CountEmpID()
{
string SelStr = < span class =code-string>从员工中选择EMPID;
SqlDataAdapter da = new SqlDataAdapter(SelStr,con);
DataTable dt = new DataTable();

da.Fill(dt);

return dt.Rows.Count;
}

// Page_Load事件:
int e_id = CountEmpID();
EmpIDTxt.Text = e_id.ToString();


用于生成 ID 字段自动实际上,使它成为身份字段,记住,它的数据类型必须是 int



谢谢


假设Empid是由数据库生成的标识值,那么在插入记录之前就无法显示它 - 它只在那时定义。想一想:如果你有两个用户运行相同的软件,他们就不能为下一次输入准备好相同的EmpId!



如果那不是'不管你想做什么,请详细解释,记住我们看不到你的屏幕,访问你的硬盘或读你的想法。 :笑:

i have created an application using EMPID and Ename how the Emp id can be generated auto matically that means it should automatically display the emp id to the textbox.

解决方案

I''m assuming that you are using SQL DB..

// Define one method
public int CountEmpID()
{
    string SelStr = "select EMPID from Employee";
    SqlDataAdapter da = new SqlDataAdapter(SelStr, con);
    DataTable dt = new DataTable();
    
    da.Fill(dt);
    
    return dt.Rows.Count;
}

//Page_Load event :
int e_id = CountEmpID();
EmpIDTxt.Text = e_id.ToString();


For generating ID field auto matically, make it identity field, Remember, its datatype must be int.

Thanks


Assuming that Empid is generated by a database as an identity value, then you cannot display it until you have inserted the record - it is only defined at that point. Think about it: if you have two users running the same software, they can''t both have the same EmpId ready for the next input!

If that isn''t what you are trying to do, then please explain in better detail, remember that we can''t see your screen, access your HDD, or read your mind. :laugh:


这篇关于如何将id自动增量到文本框中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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