Read an Image field from database using stored procedure

Hi you experts.

Is there a way to read an image field from an sql database using a stored procedure?
My problem is that all values in the rows tha are returned by the stored procedure are objects and can only be converted to string.I want to be able to take the Photo field that is being return by the stored procedure and asign it to a byte variable.

Any help will be very appreciated.

Thank you all in advance.
LVL 1
adktdAsked:
Who is Participating?
 
Bob LearnedCommented:
Yeah, you're right on that on ;)

byte[] data = (byte[]) dr["Photo"];

Bob
0
 
Bob LearnedCommented:
1) .NET version?

2) Database type?

Bob
0
 
adktdAuthor Commented:
VS.NET version 2003

Database Sql Server 2000(Unfortunatelly i preffer 2005 better)
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Bob LearnedCommented:
What do you mean by "all values in the rows that are returned by the stored procedure are objects"?

Bob
0
 
adktdAuthor Commented:
For example : If an sp returns a dataset that has one table with a column named photo and a column named EmployeeName

string empName;
Byte empPhoto;

foreach(DataRow dr in myDataSet.Table[0].rows)
{
   empname = dr["EmployeeName"].ToStirng();
   
   dr["Photo"] -------------> is object
}

How can i assign dr["Photo"] to empPhoto ?
0
 
Bob LearnedCommented:
dr["Photo"] should be a byte array.

byte[] data = dr["Photo"];

Bob
0
 
adktdAuthor Commented:
When i try to complile i get the same error as i did before "Cannot implicitly convert type 'object' to 'byte[]'
byte[] data = dr["Photo"];

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.