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?
You might be overthinking this:
byte[] imageArray = (byte[])cmd.Parameters["@Image1"].Value;
EDIT: Casted right hand side. Thanks JuanR.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.