Forum Moderators: open

Message Too Old, No Replies

ASP page for displaying db items

         

galahad2

10:09 am on Oct 12, 2009 (gmt 0)

10+ Year Member



I have an ASP site which connects to a mySQL database in order to view and amend stock.

My ASP knowledge is minimal and I've kind of inherited the site with its various problems.

This is the page which is supposed to pull data from the database and display the stock on the page:


<!--#include file="Connections/allaston.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_allaston_STRING
Recordset1.Source = "SELECT * FROM allaston.cars WHERE is_archived='N' ORDER BY Year_of_car ASC"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Function Getpic(carno)
Dim Recordset2__MMColParam
Recordset2__MMColParam = carno
Dim Recordset2
Dim Recordset2_numRows
Set Recordset2 = Server.CreateObject("ADODB.Recordset")
Recordset2.ActiveConnection = MM_allaston_STRING
Recordset2.Source = "SELECT * FROM allaston.pictures WHERE car_id = " + Replace(Recordset2__MMColParam, "'", "''") + " ORDER BY pic_position ASC"
Recordset2.CursorType = 0
Recordset2.CursorLocation = 2
Recordset2.LockType = 1
Recordset2.Open()
Recordset2_numRows = 0
Getpic = (Recordset2.Fields.Item("pic_filename").Value)
Recordset2.Close()
Set Recordset2 = Nothing
end function
%>
<%
Dim HLooper1__numRows
HLooper1__numRows = -3
Dim HLooper1__index
HLooper1__index = 0
Recordset1_numRows = Recordset1_numRows + HLooper1__numRows
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<link href="css/ALLASTON.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="scripts/mootools.js"></script>
<script type="text/javascript" src="scripts/reflection.js"></script>

<body>
<script type="text/javascript" src="scripts/wz_tooltip.js"></script>

<table width="620" border="0">

<tr>
<td class="bodycopyboldwt" width=207><div align="center">
<table>
<tr><td colspan="3" class="bodycopyboldwt"><div align="center" class="menugrey">Click on the car image for full information</div></td>
</tr>
<%
startrw = 0
endrw = HLooper1__index
numberColumns = 3
numrows = -1
while((numrows <> 0) AND (Not Recordset1.EOF))
startrw = endrw + 1
endrw = endrw + numberColumns
%>
<tr align="center" valign="top" class="bodycopyboldwt">
<%
While ((startrw <= endrw) AND (Not Recordset1.EOF))
%>
<% 'check to see if pic exists
picreq = getpic((Recordset1.Fields.Item("carid").Value))
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'If (fs.FileExists(dirrequ)=true) Then
'picrequired = picreq
'Else
'picrequired = "blank.jpg"
'End If %>

<td width="306"><img src="images/spacer.gif" width="200" height="1"/>
<a href="car_for_sale.asp?carid=<%=(Recordset1.Fields.Item("carid").Value)%>" Target="_top" onMouseOver="Tip('Click on the photo for full details of the car <%=(fs.FileExists(dirrequ)=true)%>', WIDTH, 150, SHADOW, true, FADEIN, 300, FADEOUT, 300, OFFSETY, 40)">
<img src="carpictures/<%=picreq%>" width="200" /></a>
<%=(Recordset1.Fields.Item("title").Value)%>&nbsp;<%=(Recordset1.Fields.Item("carid").Value)%><br />
<span class="bodycopyboldred">&pound;<%=(Recordset1.Fields.Item("Price").Value)%></span>&nbsp;&nbsp;<%=(Recordset1.Fields.Item("Chassis_no").Value)%><br />
<%=(Recordset1.Fields.Item("Transmission").Value)%>&nbsp;&nbsp;<%=(Recordset1.Fields.Item("Year").Value)%>&nbsp;&nbsp;<%=(Recordset1.Fields.Item("Steering").Value)%> hd<br />Colour: <%=(Recordset1.Fields.Item("Colour").Value)%><br />Interior: <%=(Recordset1.Fields.Item("Interior").Value)%><br />Hood: <%=(Recordset1.Fields.Item("Hood").Value)%></td>
<%
startrw = startrw + 1
Recordset1.MoveNext()
Wend
%>
</tr>
<%
numrows=numrows-1
Wend
%>
</table>
</div></td>

</tr>


</table>
</body>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

However...

I get this error when browsing the page:


ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/stock2.asp, line 34

Line 34 is this:

Getpic = (Recordset2.Fields.Item("pic_filename").Value)

I've checked Recordset2, which pulls from the allaston.pictures table, and there's definitely a field with that exact name (pic_filename) so not sure what's causing this problem? The Connections file contains the correct credentials for the db connection.

Apparently this sort of error can be caused by having 0 records in the Recordset but there are definitely plenty of records in there...

So somehow I need to get this page working...

Ocean10000

1:48 pm on Oct 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



'Checks to make sure we are not past the end of the record set. EOF often happens if there are no records
'matching.

If (Not Recordset2.EOF) Then
Getpic = (Recordset2.Fields.Item("pic_filename").Value)
Else
Getpic = "blank.jpg"
End If