By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,523 Members | 1,938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,523 IT Pros & Developers. It's quick & easy.

Display an image from access database

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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/article...3031201&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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.