Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get byte[] from the SqlDataReader?

I have table with 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);
like image 540
akshaykumar6 Avatar asked Dec 19 '12 08:12

akshaykumar6


1 Answers

Try GetValue() method.

byte[] b=null;
b=(byte [])obj.GetValue(0);
//OR
b=(byte [])obj[0];
like image 198
KV Prajapati Avatar answered Sep 25 '22 15:09

KV Prajapati