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. Displaying image in image control

Displaying image in image control

Scheduled Pinned Locked Moved ASP.NET
sysadmintutorial
4 Posts 4 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.
  • G Offline
    G Offline
    garga1
    wrote on last edited by
    #1

    Can anybody tell me how to retrieve a image from ms access 2003 and bind it to image control.. i hv retrieved image successfully in a new page. But want to bind it to Image control. My code is as following : Uploading to Ms access // This code works fine Dim intImageSize As Int64 Dim strImageType As String Dim ImageStream As Stream intImageSize = File1.PostedFile.ContentLength strImageType = File1.PostedFile.ContentType ImageStream = File1.PostedFile.InputStream Dim ImageContent(intImageSize) As Byte Dim intStatus As Integer intStatus = ImageStream.Read(ImageContent, 0, intImageSize) Dim MyConnection As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\MyDataBase.mdb") & "") Dim MyCommand As New Data.OleDb.OleDbCommand("INSERT INTO Images (ImageType,ImageData) VALUES (@ImgType,@img)", MyConnection) Dim prImageType As New Data.OleDb.OleDbParameter("@ImgType", 255) prImageType.Value = strImageType MyCommand.Parameters.Add(prImageType) Dim prImage As New Data.OleDb.OleDbParameter("@img", 255) prImage.Value = ImageContent MyCommand.Parameters.Add(prImage) MyConnection.Open() MyCommand.ExecuteNonQuery() MyConnection.Close() Retrieving Images from Msaccess Dim MyConnection As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\MyDataBase.mdb") & "") Dim MyCommand As New Data.OleDb.OleDbCommand("Select * from Images", MyConnection) MyConnection.Open() Dim myDataReader As Data.OleDb.OleDbDataReader myDataReader = MyCommand.ExecuteReader() ' myDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection) Do While (myDataReader.Read()) 'Response.ContentType = myDataReader.Item("ImageType") 'Response.BinaryWrite(myDataReader.Item("ImageData")) Loop MyConnection.Close() Thanks..

    E C 2 Replies Last reply
    0
    • G garga1

      Can anybody tell me how to retrieve a image from ms access 2003 and bind it to image control.. i hv retrieved image successfully in a new page. But want to bind it to Image control. My code is as following : Uploading to Ms access // This code works fine Dim intImageSize As Int64 Dim strImageType As String Dim ImageStream As Stream intImageSize = File1.PostedFile.ContentLength strImageType = File1.PostedFile.ContentType ImageStream = File1.PostedFile.InputStream Dim ImageContent(intImageSize) As Byte Dim intStatus As Integer intStatus = ImageStream.Read(ImageContent, 0, intImageSize) Dim MyConnection As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\MyDataBase.mdb") & "") Dim MyCommand As New Data.OleDb.OleDbCommand("INSERT INTO Images (ImageType,ImageData) VALUES (@ImgType,@img)", MyConnection) Dim prImageType As New Data.OleDb.OleDbParameter("@ImgType", 255) prImageType.Value = strImageType MyCommand.Parameters.Add(prImageType) Dim prImage As New Data.OleDb.OleDbParameter("@img", 255) prImage.Value = ImageContent MyCommand.Parameters.Add(prImage) MyConnection.Open() MyCommand.ExecuteNonQuery() MyConnection.Close() Retrieving Images from Msaccess Dim MyConnection As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\MyDataBase.mdb") & "") Dim MyCommand As New Data.OleDb.OleDbCommand("Select * from Images", MyConnection) MyConnection.Open() Dim myDataReader As Data.OleDb.OleDbDataReader myDataReader = MyCommand.ExecuteReader() ' myDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection) Do While (myDataReader.Read()) 'Response.ContentType = myDataReader.Item("ImageType") 'Response.BinaryWrite(myDataReader.Item("ImageData")) Loop MyConnection.Close() Thanks..

      E Offline
      E Offline
      eyeseetee
      wrote on last edited by
      #2

      I think it is always better to store the file location of the image rather then the actual image itself in the database

      We are not a Code Charity

      1 Reply Last reply
      0
      • G garga1

        Can anybody tell me how to retrieve a image from ms access 2003 and bind it to image control.. i hv retrieved image successfully in a new page. But want to bind it to Image control. My code is as following : Uploading to Ms access // This code works fine Dim intImageSize As Int64 Dim strImageType As String Dim ImageStream As Stream intImageSize = File1.PostedFile.ContentLength strImageType = File1.PostedFile.ContentType ImageStream = File1.PostedFile.InputStream Dim ImageContent(intImageSize) As Byte Dim intStatus As Integer intStatus = ImageStream.Read(ImageContent, 0, intImageSize) Dim MyConnection As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\MyDataBase.mdb") & "") Dim MyCommand As New Data.OleDb.OleDbCommand("INSERT INTO Images (ImageType,ImageData) VALUES (@ImgType,@img)", MyConnection) Dim prImageType As New Data.OleDb.OleDbParameter("@ImgType", 255) prImageType.Value = strImageType MyCommand.Parameters.Add(prImageType) Dim prImage As New Data.OleDb.OleDbParameter("@img", 255) prImage.Value = ImageContent MyCommand.Parameters.Add(prImage) MyConnection.Open() MyCommand.ExecuteNonQuery() MyConnection.Close() Retrieving Images from Msaccess Dim MyConnection As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\MyDataBase.mdb") & "") Dim MyCommand As New Data.OleDb.OleDbCommand("Select * from Images", MyConnection) MyConnection.Open() Dim myDataReader As Data.OleDb.OleDbDataReader myDataReader = MyCommand.ExecuteReader() ' myDataReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection) Do While (myDataReader.Read()) 'Response.ContentType = myDataReader.Item("ImageType") 'Response.BinaryWrite(myDataReader.Item("ImageData")) Loop MyConnection.Close() Thanks..

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        You write a http handler that takes the id of the image on the URL, reads it from the DB and streams out it's bytes. Then you use URLs pointing to that handler for the URL of your image control

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        K 1 Reply Last reply
        0
        • C Christian Graus

          You write a http handler that takes the id of the image on the URL, reads it from the DB and streams out it's bytes. Then you use URLs pointing to that handler for the URL of your image control

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          K Offline
          K Offline
          Krazy Programmer
          wrote on last edited by
          #4

          CG is absolutely correct i too did it in the same way

          If You win You need not Explain............ But If You Loose You Should not be there to Explain......

          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