Search code examples
c#sqlparameter

Supplying output parameter to sqlparametercollection resulting in error (Varbinary)


I want to supply an output parameter to my stored proc. This output proc is returning byte[]. How do I do this?

If I do the following:

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

I get:

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

Any ideas? Thanks


Solution

  • You have to give a value to the Size parameter:

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