Display Pictures from Access database

C

CJ

I have an access database located in the fpdb subfolder of my web site. One
of the fields contains an image - this image is actually stored within the
Access database, rather than being a file stored outside the database.

I want my Database Results wizard to show this picture automatically, but
all I get is << BINARY >> instead of the picture.

I found lots of help on the web about displaying pictures located outwith
the database, but this isn't what I want.

The page is located at http://www.mymea.co.uk/fred/searcha.asp

Many thanks.

CJ
 
C

CJ

I found lots of help on the web about displaying pictures located outwith
the database, but this isn't what I want.

The page is located at http://www.mymea.co.uk/fred/searcha.asp

Many thanks.

Please ignore, I found the answer:

When working with an Access OLE Object field, you are working with binary
data. Therefore you can't use the typical "Response.Write..." to display an
image stored in the database. It's really rather tricky to do, as the
database also stores a header in the field which indicates what type of
object is stored in it. In order to even work with the data, you have to
first strip out the header. The only way to do this at this point is to
build a custom COM object that strips out the header and returns a binary
stream. The problem with this (aside from having to write a custom COM
object) is getting your hosting service to register the COM object on their
server. Hosting services are not particularly fond of registering 3rd-party
COM objects on their servers.

The best thing to do if you can, is to store the images in a file on your
web, ad store the paths to the images in your database. Then you can use the
path from the database to dynamically build an image source tag.

CJ
 
X

xmas

Hi CJ,

It really is easier than all that...

http://office.microsoft.com/assista...ID=HA010346811033&CTT=6&Origin=EC010553071033

The images are put in the images folder and the database retrieves them
and inserts them in the page..

If you have acrobat Reader you might find this links page of interest.
(a zipped PDF File)

www.xmas-i-am.com/flash/fplinks.zip

xmas
=============================
| > I found lots of help on the web about displaying pictures located
outwith
| > the database, but this isn't what I want.
| >
| > The page is located at http://www.mymea.co.uk/fred/searcha.asp
| >
| > Many thanks.
| >
|
| Please ignore, I found the answer:
|
| When working with an Access OLE Object field, you are working with binary
| data. Therefore you can't use the typical "Response.Write..." to display
an
| image stored in the database. It's really rather tricky to do, as the
| database also stores a header in the field which indicates what type of
| object is stored in it. In order to even work with the data, you have to
| first strip out the header. The only way to do this at this point is to
| build a custom COM object that strips out the header and returns a binary
| stream. The problem with this (aside from having to write a custom COM
| object) is getting your hosting service to register the COM object on
their
| server. Hosting services are not particularly fond of registering
3rd-party
| COM objects on their servers.
|
| The best thing to do if you can, is to store the images in a file on your
| web, ad store the paths to the images in your database. Then you can use
the
| path from the database to dynamically build an image source tag.
|
| CJ
|
|
 
C

CJ

The images are put in the images folder and the database retrieves them
and inserts them in the page..

Thanks, that's what I'd concluded - the images are stored outside the
database rather than as an OLE object inside it. The database instead
contains just the filename of the image as a text field, and the web page
drags the image from the images folder when the results wizard runs.

That's not ideal for my purposes, because the images have to be part of the
database for another reason, and it just seemed logical to use them from
there rather than create them again on the web server.

Thanks again.

CJ
 
C

chris leeds

while it's not the db wizard, I have a script in php that pulls images from
an mysql database and writes them onto the page. i could copy the page that
does this for you.
 
C

CJ

while it's not the db wizard, I have a script in php that pulls images from
an mysql database and writes them onto the page. i could copy the page that
does this for you.

Thanks, but the databse I have is already in Access.

CJ
 
G

Guest

hey, i was buzzing the newsgroups and i can give you the code for it
its no worries, i store images in an access dbase as well using ole objec
and pull it out displaying it on the page just fine. I'm using VBScript to do it, so
i don't know about your environment, but this should help you get on the right track

Use the getimage.asp to pull the images from showimage.as
You're passing a query to the showimage.asp file which renders the image from th
Access Dbase and displays it on the getimage.asp page using the Primary Ke
from the Imagetable in the dbase you're using

I hope this helps. If you can help me figure out how to replace the OLE Object imag
from the field that would be great. i'm having issues w/ that, it doesn't want to overwrit
the image, yet it won't throw me any errors to start figuring out how to do it

incidently, if a person tries to save the image, it will save as 'showimage.asp' and open i
a text editor in binary. they'd have to know to rename it to the proper file extension of the
image itself.

I've tested this w/ png,jpg,gif and it works fine for my purposes.

cheers

James Mendha
Brave Pixel Media Cor
Vancouver, BC
(e-mail address removed)

<text listed below:

getimage.asp

<
'declare some job
Dim Conn, objRS, SQ
SQL = "SELECT * FROM <TableName> order by id desc
Set Conn = Server.CreateObject("ADODB.Connection"
'ms access dsnless connectio
dim db_connec
db_connect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<driveletter>:/<path-to-database>/<ImageDatabase>.mdb
Conn.Open db_connec
Set objRS = Server.CreateObject("ADODB.Recordset"
objRS.Open SQL, Con
%><html><HEAD><TITLE>showphoto</TITLE></HEAD><body bgcolor="#ffffff"><table cellpadding="2" cellspacing="2" border="0" width="90%"><tbody><% do while not RS.EOF %><tr valign="Top"><td valign="Top"><img src="showimage.asp?ID=<%= objRS("ID")%>" width="<%objRS("ImageWidth")%>" border="0"></td></tr><%
RS.MoveNex
Loop
%></table></body></html><
'Clean up..
objRS.Clos
Set objRS = Nothin
Conn.Clos
Set Conn = Nothin
%

showimage.as

<
dim db_connec
db_connect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/webserver/databases/PhaseMechanic.mdb
%><
REM Step 1: Read in ID from querystring in file get.as
Dim I
ID = Request.QueryString("ID"

REM Step 2: select picture from ms acces
Dim Conn, RS, SQ
SQL = "SELECT <ImageField> FROM <tableName> WHERE ImagetID = " & I

REM step 3: make a dbase connectio
Set Conn = Server.CreateObject("ADODB.Connection"

Conn.Open db_connec
Set RS = Server.CreateObject("ADODB.Recordset"
RS.Open SQL, Con

REM Step 4: Set the ContentType to image/jp
Response.ContentType = "image/jpg

REM Step 5: Use Response.BinaryWrite to output the imag
Response.BinaryWrite RS("ImageData"

RS.Clos
Set RS = Nothin
Conn.Clos
Set Conn = Nothin
%>
 
K

Kevin Spencer

This code would only work if the images were not insereted into the database
using Access, but were inserted programmatically without headers, as it does
not account for the OLE Object headers that Access creates in the field.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Jammen said:
hey, i was buzzing the newsgroups and i can give you the code for it.
its no worries, i store images in an access dbase as well using ole object
and pull it out displaying it on the page just fine. I'm using VBScript to do it, so
i don't know about your environment, but this should help you get on the right track.

Use the getimage.asp to pull the images from showimage.asp
You're passing a query to the showimage.asp file which renders the image from the
Access Dbase and displays it on the getimage.asp page using the Primary Key
from the Imagetable in the dbase you're using.

I hope this helps. If you can help me figure out how to replace the OLE Object image
from the field that would be great. i'm having issues w/ that, it doesn't want to overwrite
the image, yet it won't throw me any errors to start figuring out how to do it.

incidently, if a person tries to save the image, it will save as 'showimage.asp' and open in
a text editor in binary. they'd have to know to rename it to the proper file extension of the
image itself.

I've tested this w/ png,jpg,gif and it works fine for my purposes.

cheers,

James Mendham
Brave Pixel Media Corp
Vancouver, BC.
(e-mail address removed)

<text listed below:>

getimage.asp

<%
'declare some jobs
Dim Conn, objRS, SQL
SQL = "SELECT * FROM <TableName> order by id desc"
Set Conn = Server.CreateObject("ADODB.Connection")
'ms access dsnless connection
dim db_connect
db_connect="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source= said:
Conn.Open db_connect
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open SQL, Conn
%><html><HEAD><TITLE>showphoto</TITLE></HEAD><body
bgcolor="#ffffff"><table cellpadding="2" cellspacing="2" border="0"
width="90%"><tbody><% do while not RS.EOF %><tr valign="Top"><td
 

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

Top