4

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

Irshad
  • 3,071
  • 5
  • 30
  • 51
GurdeepS
  • 65,107
  • 109
  • 251
  • 387

2 Answers2

4

If you do not know the return size then use -1, e.g.

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

This will then return any size.

Simon C
  • 158
  • 1
  • 11
2

You have to give a value to the Size parameter:

 new SqlParameter("@Bytes", SqlDbType.VarBinary, 8000)
H H
  • 263,252
  • 30
  • 330
  • 514