如何使用DataContext.ExecuteCommand并得到执行存储过程的返回值? [英] How to use DataContext.ExecuteCommand and get the executed stored proc return value?

查看:1716
本文介绍了如何使用DataContext.ExecuteCommand并得到执行存储过程的返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#项目,我调用存储过程如下:

In a c# project, I call a stored procedure as follows:

System.Data.Linq.DataContext dataContext = MembershipContext.GetContext(connectionString);
int returnValue = dataContext.ExecuteCommand("EXEC usp_SomeProcedure {0}, {1}, {2}", param1, param2, param3);

然而,ExecuteCommand返回受影响的行数,而不是我的存储过程返回值。什么是得到这个值的最简单方法。我需要这个,因为在SP上的成功和积极的int值返回0,如果发生错误。

However, ExecuteCommand returns the number of rows affected, and not my stored procedure return value. What would be the easiest way to get this value. I need this because the SP returns 0 on success and a positive int value if an error occurred.

目前,该存储过程使用RETURN输出其返回值。不过,我可以改变这一个SELECT或者如果需要的话我还可以使用输出参数。

For now, the stored proc uses RETURN to output its return value. However, I could change this for a SELECT or I could also use an output parameter if required.

推荐答案

我相信你需要将CommandType为CommandType.StoredProcedure,为了让您的存储过程的返回值。看到这里接受的答案:<一href=\"http://stackoverflow.com/questions/3309213/getting-return-value-from-stored-procedure-in-ado-net\">Getting从存储过程在ADO.NET 返回值

I believe you need to set the CommandType to CommandType.StoredProcedure in order to get the return value from your stored proc. See the accepted answer here: Getting return value from stored procedure in ADO.NET

这篇关于如何使用DataContext.ExecuteCommand并得到执行存储过程的返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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