显示数据库中的默认用户ID [英] display user id default from database

查看:76
本文介绍了显示数据库中的默认用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我为uid赋予了身份,它自动增加了一个...
当新用户来向他注册他的帐户显示ID时...
我在页面加载事件中使用了此代码:

hi.
i given identity to the uid its automatically increased by one...
when a new user came to register the id of his account show to him...
i used this code in page load event:

con.Open();
SqlCommand cmd = new SqlCommand("select * from ownreg",con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
    TextBox10.Text = dr[0].ToString().Trim();
}
con.Close();
dr.Close();



但它显示的ID仅是1.
如何递增或显示当前ID号.



but it showing the id as 1 only.
how to increment or display the current id number.

推荐答案

SQL在初始化时具有它自己的AutoIncrement功能.
当您插入用户信息时,您的ID会自动递增.
选中 [ ^ ]
SQL has it''s own functionality of AutoIncrement on inseration use that.
As you insert users information your id get''s incremented automatically.
check this[^]


您的ID获取成功在数据库中增加了吗?
如果是,那么您可以在进行insertion时获得自动递增的id.

这是脚本.
does your id get''s incremented in database successfully ?
if yes then you can get autoincremented id while inseration.

here is script.
insert into sample values(''w'',''r'') SELECT @@Identity as test



测试列将返回新插入的自动递增的值.

完成该值并将其分配给文本框.



The test column will return newly inserted auto incremented value.

fectch the value and assign it to textbox.


更新此代码,您将获得解决方案
Update this code you get the solution
con.Open();
SqlCommand cmd = new SqlCommand("select max([your id field])+1 from  ownreg",con);
SqlDataReader dr = cmd.ExecuteReader();

if (dr.Read())
{
  TextBox10.Text = dr[0].ToString().Trim();
}

con.Close();
dr.Close();


这篇关于显示数据库中的默认用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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