Retreiving image from access DB and displaying in an ASP page

I

i.sobha

Hi,

I tried retreiving an image from an access data base and display it to
the asp page .

The code is shown below. But the same is not working. Can someone
provide me with some valuable inputs.

Save the belo code in an asp ShowPicture.asp

<%
'Declare Variables..
Dim sql
Dim rs
Dim conn
Dim userID,str
userID = Request("PhotoId")
If userID = "" Then userID = 1

'Instantiate Objects
Set conn=server.createobject("adodb.connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open "provider=Microsoft.jet.oledb.4.0;" & "Data source=C:
\test\test_image.mdb"

'Get the specific image based on the ID passed in a querystring
str = "SELECT * FROM users where user_id =" & userID
rs.Open str, conn,3,3

if rs.eof then 'No records found
Response.End
else 'Display the contents
Response.ContentType = "image/jpg"
Response.BinaryWrite(rs("user_photo"))

end if

'destroy the variables.
rs.Close
conn.Close
set rs = Nothing
set conn = Nothing
%>

2) Create another asp page image.asp with the belo code

<IMG SRC="ShowPicture.asp?PhotoId=1">

image.asp is called first which tries to get the image from
ShowPicture.asp. I seem to get the package data in binary format . No
image is getting displayed.

Thanks in advance,
Sobha
 
A

Anthony Jones

Hi,

I tried retreiving an image from an access data base and display it to
the asp page .

The code is shown below. But the same is not working. Can someone
provide me with some valuable inputs.

Save the belo code in an asp ShowPicture.asp

<%
'Declare Variables..
Dim sql
Dim rs
Dim conn
Dim userID,str
userID = Request("PhotoId")
If userID = "" Then userID = 1

'Instantiate Objects
Set conn=server.createobject("adodb.connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.open "provider=Microsoft.jet.oledb.4.0;" & "Data source=C:
\test\test_image.mdb"

'Get the specific image based on the ID passed in a querystring
str = "SELECT * FROM users where user_id =" & userID
rs.Open str, conn,3,3

if rs.eof then 'No records found
Response.End
else 'Display the contents
Response.ContentType = "image/jpg"
Response.BinaryWrite(rs("user_photo"))

end if

'destroy the variables.
rs.Close
conn.Close
set rs = Nothing
set conn = Nothing
%>

2) Create another asp page image.asp with the belo code

<IMG SRC="ShowPicture.asp?PhotoId=1">

image.asp is called first which tries to get the image from
ShowPicture.asp. I seem to get the package data in binary format . No
image is getting displayed.

I don't do a great deal of Jet however 1) are you sure the stored binary is
in JPEG format and 2) the mimetype of a JPEG is image/jpeg.
 

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,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top