Display an image from access database

G

Guest

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
 
J

Jason DeFontes

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top