0

My database is SQL Server. In that one photo data column is there. That is varbinary datatype. How to retrieve the original image from that code. Please suggest any better way

Regards, Pradeep

1
  • 2
    This question must have been answered hundreds of times on the web already. It is duplicate. Commented Feb 7, 2013 at 13:25

1 Answer 1

1

VarBinary is binary - so cast the field in the resultset to byte[]

byte[] bytes = (byte[])dataReader["fieldname"];

Then use a MemoryStream to convert the bytes to Image

public Image BytesToImage(byte[] bytes)
{
     using(MemoryStream ms = new MemoryStream(bytes))
     {
         Image image = Image.FromStream(ms);
         return image;
     }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.