您的位置:程序门 -> .net技术 -> vb.net



怎样得到刚写入的标识字段的记录值?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎样得到刚写入的标识字段的记录值?
发表于:2008-02-15 17:55:01 楼主
insert了一条记录,想立刻得到标识字段的值,怎么写
发表于:2008-02-15 18:11:051楼 得分:0
在一条   insert、select   into   或大容量复制语句完成后,@@identity   中包含语句生成的最后一个标识值。如果语句未影响任何包含标识列的表,则   @@identity   返回   null。如果插入了多个行,生成了多个标识值,则   @@identity   将返回最后生成的标识值。

@@identity   函数的作用域是执行该函数的本地服务器上的当前会话。

sql code
use adventureworks; go --display the value of locationid in the last row in the table. select max(locationid) from production.location; go insert into production.location (name, costrate, availability, modifieddate) values'damaged goods', 5, 2.5, getdate()); go select @@identity as 'identity'; go --display the value of locationid of the newly inserted row. select max(locationid) from production.location; go
发表于:2008-02-15 18:17:462楼 得分:0
能不能告诉我在vb.net中怎么把这个读出来


快速检索

最新资讯
热门点击