如何在添加新行时使用(DataSet)在sql server中获取序列ID? [英] how to get sequence id in sql server with (DataSet) when add new Row ?

查看:79
本文介绍了如何在添加新行时使用(DataSet)在sql server中获取序列ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DataSet连接sql server,我想点击按钮(+) 从sql server添加新行获取序列id  然后 点击 保存行 :

I'm use DataSet to connection with sql server , I want when click to button (+) add new row get sequence id from sql server And then click to Save Rows :

select NEXT VALUE FOR Id_Sequence as Id_Sequence





推荐答案

您好,

在多用户系统中工作时,下一个可用的主键值不可靠,因此请事先了解这一点。考虑两个用户输入新记录。您获得新密钥然后他们发布新记录,您拥有的价值无效,只有一次。

The next available primary key value is unreliable when working in a multi-user system so know this up front. Consider two users enter a new record. You get the new key then they post the new record, the value you have is not valid, it's one off.

如果您想尝试以下内容,请考虑以上因素。

If you want to try the following with the above in mind.

SELECT IDENT_CURRENT('dbo.YourTableName') +1;

我在这里创建新查询

使用它

Dim nextIdentifier As Decimal? = CustomerTableAdapter.GetNextPrimaryKey
MessageBox.Show(nextIdentifier.ToString)

现在说我还没试过"使用"按下"+"时的新主键。按钮。将让你通过这个工作。

Now with that said I have not tried to "use" the new primary key for when pressing the "+" button. will let you work thru this.

最后一件事,当发布一条新记录时,在插入后直接有代码通过SELECT CAST(scope_identity()AS获取该行的密钥int)你没看到但是它就在那里。

One last thing, when posting a new record, internally there is code directly after the insert to get that row's key via SELECT CAST(scope_identity() AS int) which you don't see but it's there.


这篇关于如何在添加新行时使用(DataSet)在sql server中获取序列ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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