相关疑难解决方法(0)

存储过程返回null作为输出参数

我有stored procedure,它在MS SQL管理工作室很棒.

当我尝试在VS行中使用它时返回正常,但输出参数的值为NULL.

SqlCommand cmd = new SqlCommand("proc_name", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@p_SomeVal", SqlDbType.Int));
cmd.Parameters["@p_SomeVal"].Direction = ParameterDirection.Output;

rdr = cmd.ExecuteReader();
//...process rows...

if (cmd.Parameters["@p_SomeVal"].Value != null)
SomeVal = (int)cmd.Parameters["@p_SomeVal"].Value;
Run Code Online (Sandbox Code Playgroud)

cmd.ExecuteNonQuery(); 有相同的结果.

USE [db_name]
GO

DECLARE @return_value int,
    @p_SomeValue int

EXEC    @return_value = [dbo].[Proc_name]
    @p_InputVal = N'aa',
    @p_SomeValue = @p_SomeValue OUTPUT

SELECT  @p_SomeValue as N'p_SomeValue'

SELECT  'Return Value' = @return_value

GO
Run Code Online (Sandbox Code Playgroud)

c# sql stored-procedures

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

sql ×1

stored-procedures ×1