I am trying to get a byte array from my SQL Server parameter. I get the data from SQL Server like this:
cmd.Parameters.Add("@Image1", SqlDbType.VarBinary).Size = 5000000;
cmd.Parameters["@Image1"].Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
string str = cmd.Parameters["@Image1"].Value.ToString();
I get the value System.Byte[] in string however I would need the whole byte array that I could store it as an image.
How would I do it using .Value returns an object would I convert that object to byte array?
string str = cmd.Parameters["@Image1"].Value as byte[];?System.Byte[]when you call theToStringmethod tells you the value is already of the type you expect. All you need to do is assign the type-casted value to a variable.