c# - MVC4 使用 linq to sql 返回存储过程输出

标签 c# sql asp.net-mvc linq asp.net-mvc-4

我对下面的线程有类似的问题 ASP.NET MVC4 return output from a stored procedure with Entity Framework

我试过同样的事情,但我得到了错误:

Cannot assign void to an implicitly-typed local variable on

这是我的程序:

create PROCEDURE [dbo].[usp_UpdateValuesInTables]  
(  
    @s_clientid int,
    @success int output
)  
AS  
BEGIN  
    Begin Try
        BEGIN TRAN  
            ---- sql statements
        COMMIT TRAN 
        set @success=1 
    End Try
    Begin Catch
        ROLLBACK TRAN  
        set @success=0  
    End Catch
END 

和c#代码

int? success = null;
var successCode = Context.usp_UpdateValuesInTables(Convert.ToInt32(obj.SourceClientDropDown),ref success);

为什么会出现该错误?

如果我尝试将 var 替换为 int,则会出现错误

Can not implicitly convert type void to int

最佳答案

试试这个:

int? success = null;
Context.usp_UpdateValuesInTables(Convert.ToInt32(obj.SourceClientDropDown),ref success);
var successCode = success; //success is the returned result.

关于c# - MVC4 使用 linq to sql 返回存储过程输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19077762/

相关文章:

c# - Visual Studio - DDD 模块和洋葱

c# - 我如何在 C# 中加密 web.config 变量

c# - 连续正确地从串口异步读取

asp.net-mvc - 使用复选框绑定(bind)到具有强类型 MVC View 的 bool 列表列表字典

c# - PayPal 定期捐款分期付款

mysql - 带左连接的sql最小值

sql - 在特定组之后在 SQL 输出中动态创建行

python - 通过 python informixdb 寻找 informix 的 SQL 插入语法

asp.net-mvc - 如何在MVC4中隐藏URL参数

asp.net-mvc - 为什么 DisplayFor 不向 Action 方法发布值?