Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 396585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:34:00+00:00 2026-05-12T16:34:00+00:00

I am using a SqlDataReader and I am trying to read from a table

  • 0

I am using a SqlDataReader and I am trying to read from a table I converted from an Access file, and is in SQL Server 2008.

The datatype is now a varbinary(max).

How do I convert this, so I can have it as System.Drawing.Image?

It is a Windows MetaFile and I want to convert it to a PNG or GIF and save it to the filesystem.

It appears this won’t be correct as I get an error that it can’t convert to Image.

System.Drawing.Image LocationImage = sdr.GetSqlBinary(2)

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:34:00+00:00Added an answer on May 12, 2026 at 4:34 pm

    Use SqlBytes. Use Image.FromStream to load the image from the SqlBytes.Stream. Use CommandBehavior.SequentialAccess on the reader to load large size images:

    using (SqlDataReader sdr=cmd.ExecuteReader(CommandBehavior.SequentialAccess))
    {
    ...
    System.Data.SqlTypes.SqlBytes imageBytes = srd.GetSqBytes(2);
    System.Drawing.Image locationImage = Image.FromStream(imageBytes.Stream);
    }
    

    To save it as PNG/GIF:

    SqlCommand cmd = new SqlCommand("update table set image=@image where ...")
    
    MemoryStream streamOutput = new MemoryStream();
    image.Save(streamOutput, ImageFormat.Png);
    SqlBytes imageBytes = new SqlBytes(streamOutput); 
    cmd.Parameters.AddWithValue("@image", imageBytes);
    cmd.ExecuteNonQuery()
    

    Update

    I’m not sure Image.FromStream can load WMF format. It can load EMF afaik, but I’m not sure about WMF. Perhaps routing the call through a Metafile(Stream) constructor will work, I’m not a graphics expert by any stretch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SqlDataReader and need to read a varbinary(max) column from it using
I am using SQL Server 2008 in a asp.net/c# program. I am trying to
I am currently trying to grab some rows from a SQL Server database using
I am trying to connect to the SQL Server from Visual Web Developer using
I am trying to select food_ItemName and food_UnitPrice from t_Food table in SQL Server
I'm having a problem with deadlock on SELECT/UPDATE on SQL Server 2008. I read
I'm using Visual Web Developer 2010 Express and SQL Server 2008 R2 Management Studio
I'm trying to find optimal (fast vs easiest) way to access SQL Server code
I am trying to read a smallint column value using SqlDataReader. The dataReader.GetInt32() is
i m trying to retrieve the Specialization ID from a table called Specializationtbl, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.