473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Display an image from access database

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
1 2867
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
3
by: RAllsopp | last post by:
I have a client who would like to have several pictures associated with one system. I have read about storing only the pathname to save OLE overhead and have set-up a form for my client to...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
3
by: Sandi | last post by:
I have a simple problem: I have an Access database (images.mdb) that has 2 columns: one is the id if the picture (an integer) and one (column named picture) is a field of type OLE Object which...
2
by: Wayne Wengert | last post by:
I am trying to build an ASP.NET application which includes the capability to allow users to save pictures to a SQL Server 2000 database table and then later to display selected photos (usually JPG...
3
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating...
7
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
3
by: nudma | last post by:
Hi everyone!! I m trying to display jpg image from ms-access database on C# web page. Image is stored as OLE object under "img_stream" variable in database. Here is my code: String connStr =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.