Retreiving image from access DB and displaying in an ASP page
am 28.09.2007 12:44:14 von i.sobhaHi,
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
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