Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Retrieve image from Sql

Retrieve image from Sql

Scheduled Pinned Locked Moved ASP.NET
helpcsharpdatabasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VanithaVasu
    wrote on last edited by
    #1

    I am trying to display the Image which i have retrieved from Sql . The problem is i am not able to convert the bytes to image in my webform. This is my Code. SqlCommand scmd = new SqlCommand ("select mImage from MyTable where Title='"+ TextBox1.Text + "'", sqlConn); sqlConn.Open(); Byte[] storedImage = (Byte[])scmd.ExecuteScalar(); Using this i have retrieved the image But how can i display it in the Image control. Can anybody help me to solve this using C#.

    VanithaVasu

    M V 2 Replies Last reply
    0
    • V VanithaVasu

      I am trying to display the Image which i have retrieved from Sql . The problem is i am not able to convert the bytes to image in my webform. This is my Code. SqlCommand scmd = new SqlCommand ("select mImage from MyTable where Title='"+ TextBox1.Text + "'", sqlConn); sqlConn.Open(); Byte[] storedImage = (Byte[])scmd.ExecuteScalar(); Using this i have retrieved the image But how can i display it in the Image control. Can anybody help me to solve this using C#.

      VanithaVasu

      M Offline
      M Offline
      Mark Churchill
      wrote on last edited by
      #2

      Take a step back and think about how HTML works. The browser gets the page from the server. The IMG tag in the page points to where the image data is located. The browser makes a seperate request to get the image. You will need to implement another page (better still an ashx handler), which can write that byte[] out, and set the Response.ContentType to image/jpeg (whatever). Also please have a google for "SQL Injection" and "Parameterized Queries", because as your code stands now, I can delete anything out your database by typing nasty things into TextBox1...

      Mark Churchill Director Dunn & Churchill Free Download:
      Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.

      1 Reply Last reply
      0
      • V VanithaVasu

        I am trying to display the Image which i have retrieved from Sql . The problem is i am not able to convert the bytes to image in my webform. This is my Code. SqlCommand scmd = new SqlCommand ("select mImage from MyTable where Title='"+ TextBox1.Text + "'", sqlConn); sqlConn.Open(); Byte[] storedImage = (Byte[])scmd.ExecuteScalar(); Using this i have retrieved the image But how can i display it in the Image control. Can anybody help me to solve this using C#.

        VanithaVasu

        V Offline
        V Offline
        VanithaVasu
        wrote on last edited by
        #3

        But in my application i am not going to ask user to type the image names and etc , and i am working in vs.net 2.0 with C#. Actually my problem is i have to display different images in treenode of a treeview for that i have stored the details and the images in the sql and i have retrieved the image too. But the thing is i am not able to display the images in my webform. So is there any way to display the images.

        VanithaVasu

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups