在将数据插入数据库之前/之前获取新的ID [英] get new id before/while inserting data into DB

查看:248
本文介绍了在将数据插入数据库之前/之前获取新的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在按钮提交 - CODE级别C#中插入数据之前/同时获取Id(IDENTITY)的新值?

Is is possible to get new values for Id (IDENTITY) before/while inserting data in a table on Button Submit - CODE level C#?

推荐答案

您可以从 SQL Server 获取 Id 的下一个值,例如参见设置下一个身份值 [ ^ ]。如果你做了(有点不安全)的假设,只有你的代码处理表而不是你可能记录 IDENT_CURR IDENT_INCR 值以便计算下一个。
You can get the next value of the Id from SQL Server, see, for instance get the next value of identity[^] . if you make the (somewhat unsafe) assumption that only your code deals with the table than you may record IDENT_CURR and IDENT_INCR values in order to compute next ones.


使用随机函数在C#中生成随机numbur
Use random function to generate the random numbur in C#


SELECT IDENT_CURRENT('TableName')为您提供当前Id(IDENTITY)。
SELECT IDENT_CURRENT('TableName') gives you the current Id(IDENTITY).


这篇关于在将数据插入数据库之前/之前获取新的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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