retrieve and display picture from a sql server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dgaIL
    New Member
    • Apr 2012
    • 4

    retrieve and display picture from a sql server

    Hi Guys!

    I need help to retrieve a picture stored in a sql server DB.
    In the upload process I have converted an image to Binary Data, but I have problems converting it back to a .jpg image... and display it in a form as a picture.

    I'm working with asp.net c# visual studio 2010

    Please help me!
    Thanks!
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    Show us the code you're using to retrieve your image and display it and someone will help you find a solution to your problem.

    Comment

    • dgaIL
      New Member
      • Apr 2012
      • 4

      #3
      thanks man!, but I will just save the picture as a picture inside a folder, according to what you had recommended in this other thread.
      Thanks :)
      Last edited by Frinavale; Apr 11 '12, 06:23 PM. Reason: Added a link to the other thread.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        It's really not that hard to retrieve it from a database.

        You would need a column in a table that is a blob/image/something-that-can-hold-bytes (depending on the database that you're using). In your case the column would be an Image type since you're using Microsoft's Sql Server

        When you save the image into the database, you would read the bytes in the image into memory (a byte array) and then save that into the column in your database.

        When you retrieve the image, you will have to grab the byte array from the column and convert it into the image type of your choice. The image type that you create really all depends on the type of application you're developing...in the case of a web application, you would just write it to the response.output stream and change the headers to indicate to the browser that you are sending an image (as apposed to HTML that is usually sent).

        -Frinny

        Comment

        Working...