在一个c#项目中,我调用了一个存储过程如下:
System.Data.Linq.DataContext dataContext = MembershipContext.GetContext(connectionString);
int returnValue = dataContext.ExecuteCommand("EXEC usp_SomeProcedure {0}, {1}, {2}", param1, param2, param3);
但是,ExecuteCommand 返回受影响的行数,而不是我的存储过程返回值。获得此值的最简单方法是什么。我需要这个,因为 SP 在成功时返回 0,在发生错误时返回正整数值。
目前,存储过程使用 RETURN 来输出它的返回值。但是,我可以为 SELECT 更改它,或者如果需要我也可以使用输出参数。
最佳答案
我认为您需要将 CommandType 设置为 CommandType.StoredProcedure 才能从存储过程中获取返回值。在此处查看已接受的答案:Getting return value from stored procedure in ADO.NET
关于c# - 如何使用DataContext.ExecuteCommand 获取执行后的存储过程返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11654610/