Retreiving image from access DB and displaying in an ASP page

Retreiving image from access DB and displaying in an ASP page

am 28.09.2007 12:44:14 von 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



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

Re: Retreiving image from access DB and displaying in an ASP page

am 28.09.2007 13:48:32 von Anthony Jones

wrote in message
news:1190976254.282085.301150@w3g2000hsg.googlegroups.com...
> 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
>
>
>
> 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.



--
Anthony Jones - MVP ASP/ASP.NET