Getting binary image data from SQL Server

G

Guest

I have a stored procedure that returns the binary representation of an image
from a SQL Server db. The following code returns an "Invalid parameter"
error on the System.Drawing... line. I am converting this code from Access.
Any ideas? Thanks!

byte[] imageData = (byte[])(command.ExecuteScalar());
MemoryStream ms = new MemoryStream(imageData);
System.Drawing.Image fullsizeImage = System.Drawing.Image.FromStream(ms);
 
G

Guest

NathanV said:
I have a stored procedure that returns the binary representation of an image
from a SQL Server db. The following code returns an "Invalid parameter"
error on the System.Drawing... line. I am converting this code from Access.
Any ideas? Thanks!

byte[] imageData = (byte[])(command.ExecuteScalar());
MemoryStream ms = new MemoryStream(imageData);
System.Drawing.Image fullsizeImage = System.Drawing.Image.FromStream(ms);

I don't believe that this is an appropriate use of ExecuteScale()... try
using ExecuteReader( CommandBehaviour.SingleResult) and then use the
GetBytes() member of the resulting DataReader instance.

Hope that helps,

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,477
Members
44,898
Latest member
BlairH7607

Latest Threads

Top