Reputation: 2257
I have a table with a varbinary(MAX) parameter. After executing the query, I will store the result in SqlDataReader as it has multiple columns as output.
SqlCommand cmd = new SqlCommand("select leave_details from LeaveTable");
SqlDataReader obj;
con.Open();
obj = cmd.ExecuteReader();
Now I want to convert the result for each row into byte[]
.
This one is not working:
byte[] b=null;
obj.GetBytes(0,0,b,0,1024);
Upvotes: 21
Views: 36644
Reputation: 13592
string bytesfromsql = "01010101010110010111010001"; //for example
byte[] bytes = new byte[bytesfromsql.Length];
for (int i = 0; i < bytes.Count(); i++)
{
bytes[i] = byte.Parse(bytesfromsql[i].ToString());
}
Upvotes: 0
Reputation: 94653
Try GetValue()
method.
byte[] b=null;
b=(byte [])obj.GetValue(0);
//OR
b=(byte [])obj[0];
Upvotes: 42