Display an image from access database

Discussion in 'ASP .Net' started by =?Utf-8?B?RXJpYyBLZXVuZw==?=, May 14, 2004.

  1. Hi all,

    my case is I want to get an image from access database and I just know it's "OLE object" field type at access
    I also don't know how to insert it into access

    here is my code and it just can display a invalid image

    try
    dim strConn as string
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath
    ("ERIC_TEST_V05.mdb") & "; Jet OLEDB:Database Password=123456;"

    Dim objConn as New OleDBConnection(strConn)
    objConn.Open()

    Dim objCmd as New OleDbCommand()
    objCmd.Connection = objConn
    objCmd.CommandText = "SELECT logo FROM office_profile"

    Dim objReader as OleDbDataReader
    objReader = objCmd.ExecuteReader

    While objReader.Read
    'Response.BinaryWrite(objReader("logo") & "<br>")

    Dim bindata() As Byte = objReader.GetValue(0)

    Response.Clear()
    Response.ContentType = "Image/bmp"
    Response.BinaryWrite ( bindata )

    End While

    objConn.close()
    catch ex as exception
    response.write (ex.tostring())
    end try

    Please help .

    Regards,
    Eric Keung
     
    =?Utf-8?B?RXJpYyBLZXVuZw==?=, May 14, 2004
    #1
    1. Advertising

  2. The problem is, when you insert an image into an Access database using
    Insert/Object from the Access menu, it doesn't just store the raw binary
    data of the file. It stores it as an OLE object which contains that data
    and has some kind of wrapper that's able to activate the OLE object so
    you can view/edit it from within and Access form.

    Cool for Access, but not good if you're trying to display it on the web.
    If you just stream out the data of the OLE object like you're doing,
    it's not in the format that a browser can recognize as valid image data.

    The only way to get this to work is to programatically insert the data
    into Access, so you can write only the raw image data and not the OLE
    wrapper. Then when you pull the data out and stream it to the browser it
    will be in a format that the browser can display.

    I've done this before, but I can't find the code that I used. Here's an
    article that might be helpful though:

    http://www.stardeveloper.com/articles/display.html?article=2003031201&page=1

    -Jason

    Eric Keung wrote:

    > Hi all,
    >
    > my case is I want to get an image from access database and I just know it's "OLE object" field type at access
    > I also don't know how to insert it into access
    >
    > here is my code and it just can display a invalid image
    >
    > try
    > dim strConn as string
    > strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath
    > ("ERIC_TEST_V05.mdb") & "; Jet OLEDB:Database Password=123456;"
    >
    > Dim objConn as New OleDBConnection(strConn)
    > objConn.Open()
    >
    > Dim objCmd as New OleDbCommand()
    > objCmd.Connection = objConn
    > objCmd.CommandText = "SELECT logo FROM office_profile"
    >
    > Dim objReader as OleDbDataReader
    > objReader = objCmd.ExecuteReader
    >
    > While objReader.Read
    > 'Response.BinaryWrite(objReader("logo") & "<br>")
    >
    > Dim bindata() As Byte = objReader.GetValue(0)
    >
    > Response.Clear()
    > Response.ContentType = "Image/bmp"
    > Response.BinaryWrite ( bindata )
    >
    > End While
    >
    > objConn.close()
    > catch ex as exception
    > response.write (ex.tostring())
    > end try
    >
    > Please help .
    >
    > Regards,
    > Eric Keung
     
    Jason DeFontes, May 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandi
    Replies:
    3
    Views:
    1,779
    Natty Gur
    Nov 6, 2003
  2. Olav Tollefsen

    How to display image blob from database?

    Olav Tollefsen, Apr 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,395
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 25, 2004
  3. =?Utf-8?B?U1M=?=
    Replies:
    3
    Views:
    3,856
    Juan T. Llibre
    May 15, 2005
  4. Replies:
    1
    Views:
    1,271
    Metalore
    Oct 18, 2006
  5. Replies:
    1
    Views:
    228
Loading...

Share This Page