使用DataAccessApplicationBlock得到存储过程的返回值

来源:互联网 发布:如何安装淘宝千里眼 编辑:程序博客网 时间:2024/06/13 22:30
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
今天有位朋友问我如何在Data Access Application Block中得到存储的过程的返回值,我才发现自己以前写的文章中确实没提到这方面的问题,现在来补充一下,具体的解决方法如下:

1、首先建立一个具有返回值的存储过程,作为示例,我就简单的建一个存储过程,如下:
create proc test
(
@id int
)
as

declare @flag int

select * from person where id=@id

if @@rowcount > 0
set @flag=1
else
set @flag=0

return @flag
我们要在程序中获得这个返回值的方法如下:

[TestMethod]
public void TestReturnValue()
{
Database db = DatabaseFactory.CreateDatabase();

DbCommand dbcomm = db.GetStoredProcCommand("test");

db.AddInParameter(dbcomm, "@id", DbType.Int32,1);
//关键在这里,添加一个参数,类型为ReturnValue
db.AddParameter(dbcomm, "@RETURN_VALUE", DbType.String, ParameterDirection.ReturnValue, "", DataRowVersion.Current, null);
db.ExecuteNonQuery(dbcomm);

int testvalue = (int)dbcomm.Parameters["@RETURN_VALUE"].Value;

Assert.AreEqual(testvalue, 1);
}
通过上面的代码我们就能够在程序中获得存储过程的返回值了。

以前写的文章可能还有很多地方没说到,希望能有更多的朋友提意见,谢谢!

http://pw.cnblogs.com/archive/2006/06/19/429455.html

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击