在C#中获取价值回归@@ IDENTITY [英] Retrieving the value of RETURN @@IDENTITY in C#
本文介绍了在C#中获取价值回归@@ IDENTITY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是一个非常简单的问题。我有一个插入一行到一个表,并在年底有语句RETURN @@ IDENTITY的SP。我似乎无法找到一个方法来检索在C#中这个值。我使用的企业库,并使用方法:
db.ExecuteNonQuery(CMD);
我已经试过 cmd.Parameters [0] .value的即可获得价值,但返回0所有的时间。任何想法?
解决方案
尺寸C作为新的SqlCommand(...)
昏暗ð作为新的SqlParameter()
d.Direction = ParameterDirection.ReturnValue
c.parameters.add(D)
c.executeNonQuery
(@@ IDENTITY)= d.value
这或多或少是这样......这个或从存储过程作为输出参数只返回值。
Here's a very simple question. I have an SP that inserts a row into a table and at the end there's the statement RETURN @@IDENTITY. What I can't seem to find is a way to retrieve this value in C#. I'm using the Enterprise library and using the method:
db.ExecuteNonQuery(cmd);
I've tried cmd.Parameters[0].Value to get the value but that returns 0 all the time. Any ideas?
解决方案
Dim c as new sqlcommand("...")
Dim d As New SqlParameter()
d.Direction = ParameterDirection.ReturnValue
c.parameters.add(d)
c.executeNonQuery
(@@IDENTITY) = d.value
It is more or less like this...either this or just return the value from a stored procedure as an output parameter.
这篇关于在C#中获取价值回归@@ IDENTITY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文