c# - 向 sqlparametercollection 提供输出参数导致错误 (Varbinary)

标签 c# sqlparameter

我想为我的存储过程提供一个输出参数。此输出过程返回 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).

有什么想法吗? 谢谢

最佳答案

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

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

然后这将返回任何尺寸。

关于c# - 向 sqlparametercollection 提供输出参数导致错误 (Varbinary),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3036319/

相关文章:

c# - 从 OleDbCommand 返回值

c# - 关闭虚拟机会将所有虚拟机状态返回为未知

c# - 使用 NTLM 身份验证获取用户和组详细信息

c# - 参数化查询被截断,参数丢失

unit-testing - 如何测试 SqlParameter 是否相等

c# - SqlParameter 不允许表名 - 没有 sql 注入(inject)攻击的其他选项?

c# - 综合安全

c# - .Net Core 3.1 HttpClient 不重用套接字

c# - 哪个 MySQL 连接更适合与 C# 一起使用?

c# - 将 null 分配给 SqlParameter