Print Page | Close Window

Displaying image using database

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=15256
Printed Date: 30 March 2026 at 5:05am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Displaying image using database
Posted By: pjb007
Subject: Displaying image using database
Date Posted: 27 May 2005 at 12:13pm

I have an access database one of the fields is called images.

I have tested the database connecting works be displating the AutoNum data so I know that the connection string works.
 
in the images field there are filepaths to images
/images/image1.gif
/images/image2.gif
/images/image3.gif
/images/image4.gif
/images/image5.gif
 
For Example.
 
However when I write the ASP to display the image they won't display.
 
This is the current code I am using

Response.Write ("<p/>") %> <img src="images/ <% Response.Write (RSUser("image")) %>" >   <%
 
I have tried a few others but can't get it to work.
 
 



Replies:
Posted By: dj air
Date Posted: 27 May 2005 at 12:55pm
<%
Response.Write ("<p/>") %>
<img src="images/<%= RSUser("image") %>" >

try that


Posted By: pjb007
Date Posted: 27 May 2005 at 1:01pm
I assume I need to reopen the ASP so add a <% to the end, tried both.
 
Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/tv/test.asp, line 47
<%Response.Write ("<p/>")


Posted By: dj air
Date Posted: 27 May 2005 at 1:03pm
can we see the whole code around the area and also post whats on line 47 and aroun d those lines.


Posted By: pjb007
Date Posted: 27 May 2005 at 1:21pm
Originally posted by dj air dj air wrote:

 

<%
Response.Write ("<p/>") %>
<img src="images/<%= RSUser("image") %>" >
 
try that
 
Its working now, just spotted what was wrong the first<% was already open, just deleted it and the images are now displaying!


Posted By: pjb007
Date Posted: 27 May 2005 at 3:12pm
Well it works to a point then fails.
 

<%
dim Conn
dim FilePath
dim SQL
Dim RsUser
'Connection to Database

Set Conn = Server.CreateObject("ADODB.Connection")
FilePath = Server.MapPath("db.mdb")
Conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & FilePath & ";"
 
'SQL Query String

SQL = "Select image FROM tbltest ORDER By num"
'Set the Recordset

Set RSUser = Conn.Execute (SQL)
'Print the Recordset

RSUser.movefirst
Do while not RSUser.EOF
 'Response.Write("num")
 Response.Write ("<p/>") %> <img src="images/<%= RSUser("image") %>" >
<%
             
           
            
          Response.Write "<br/>"
         
 
   'Response.Write ("</p>")
RSUser.movenext
Loop

%>
 
Is there anything missing in the above, Does the connection to the database need to be closed, I am not sure how you do that 100%.


Posted By: dj air
Date Posted: 27 May 2005 at 3:57pm
try


<% 
dim Conn dim FilePath dim SQL Dim RsUser

'Connection to Database

Set Conn = Server.CreateObject("ADODB.Connection") FilePath = Server.MapPath("db.mdb") Conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & FilePath & ";"

 

'SQL Query String

SQL = "Select image FROM tbltest ORDER By num"

'Set the Recordset

Set RSUser = Conn.Execute (SQL)

'Print the Recordset

RSUser.movefirst
Do while not RSUser.EOF

 'Response.Write("num")

 Response.Write ("<p/>")
response.write ("<img src=""images/" & RSUser("image") &""" >")

Response.Write "<br/>"         

   'Response.Write ("</p>")

RSUser.movenext

Loop

%>


the above looks fine. the above that i pasted also is just a response.write version..

what problem are you getting


Posted By: pjb007
Date Posted: 27 May 2005 at 5:01pm
OK its working, and displaying everything proberly.  However once the page has loaded, if I het F5 to refresh it does not display and gives this error.
 
Error Type:
Provider (0x80004005)
Unspecified error
/tv/test.asp, line 32
 
Here is a screen shot of the code
%>
 
Sorry cut that off the end!


Posted By: dj air
Date Posted: 27 May 2005 at 5:32pm
whats on line 32?

also after loop add this below

RSUser.close
Conn.close
SET RSUser = Nothing
SET Conn = Nothing


really need to know whats on line 32, if its Conn.open then the above code i said add might fix it


Posted By: pjb007
Date Posted: 27 May 2005 at 6:28pm
Added those lines, still get the error
 
The line with the error is the one that starts
Conn.Open
 
It loads but when I erfresh it does not work and I get the error in the above post.


Posted By: dj air
Date Posted: 27 May 2005 at 6:52pm
ok its toi do with the connection to the database compact and repair it, and re upload, it maybe slightly corrupt,

shouldn't happen really s you are closing all conections and SETS.

only thing i can think is that its holding the connection or something.


Posted By: ub3rl337ch3ch
Date Posted: 29 May 2005 at 8:54pm
add the conn.close but not the set conn = nothing, as it stops the script from thinking of the conn variable as a connection object. either that or close the set then re-set conn as a connection object...



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net