2010-06-14 66 views
2

我想爲我的存儲過程提供一個輸出參數。此輸出過程返回byte[]。我該怎麼做呢?向sqlparametercollection提供輸出參數導致錯誤(Varbinary)

如果我做到以下幾點:

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). 

任何想法? 感謝

回答

2

你必須給一個值尺寸參數:

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

如果你不知道回報大小,然後用-1,例如

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

這將返回任何大小。