【问题标题】:Supplying output parameter to sqlparametercollection resulting in error (Varbinary)向 sqlparametercollection 提供输出参数导致错误(Varbinary)
【发布时间】:2010-06-14 09:59:40
【问题描述】:

我想为我的存储过程提供一个输出参数。此输出过程返回byte[]。我该怎么做呢?

如果我执行以下操作:

command.Parameters.Add(new SqlParameter("@Bytes", SqlDbType.VarBinary));
command.Parameters[1].Direction = ParameterDirection.Output;

我明白了:

System.InvalidOperationException: Byte[][1]: the Size property has an invalid size of 0. This stored proc works fine in SQL Server when I execute it via the SSMS option "Execute Stored Procedure).

有什么想法吗? 谢谢

【问题讨论】:

    标签: c# sqlparameter


    【解决方案1】:

    如果您不知道返回大小,则使用 -1,例如

    New SqlParameter("@PreviewImage", SqlDbType.VarBinary) With {.Direction = ParameterDirection.Output, .Size = -1}
    

    这将返回任何大小。

    【讨论】:

      【解决方案2】:

      你必须给 Size 参数一个值:

       new SqlParameter("@Bytes", SqlDbType.VarBinary, 8000)
      

      【讨论】:

        猜你喜欢
        • 2023-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多