taurang
04-28-2004, 01:52 PM
I experienced an error when doing recordset paging of search results. When the search term is blank or in the database, it work's fine. The problem occurs when it's not in the database and search term is not blank. The error message is as follows:
ADODB.Recordset error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/anandatravel/candystore/MPSearch.asp, line 101
I'm using adOpenStatic cursor type because only this supports paging. I suspect that when search term is not blank and cannot be found, EOF is true. Is this the cause of the error? How do I solve this problem? Thanks in advance.
<%
cat = TRIM( Request( "cat" ) )
IF cat = "" THEN cat = "Home"
searchFor = TRIM( Request( "searchFor" ) )
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open(conStr)
%>
<%
' Get the Current Page
pg = TRIM( Request( "pg" ) )
IF pg = "" THEN pg = 1
sqlString = "SELECT product_id, product_name, product_briefDesc " &_
"FROM Products " &_
"WHERE product_status = 1 " &_
"AND ( product_name LIKE '%" & searchFor & "%' " &_
"OR product_briefDesc LIKE '%" & searchFor & "%') " &_
"ORDER BY product_name "
Set RS = Server.CreateObject( "ADODB.Recordset" )
RS.CursorType = adOpenStatic
RS.ActiveConnection = Con
RS.PageSize = 8
RS.Open sqlString
RS.AbsolutePage = pg
%>
<% IF NOT RS.EOF AND searchFor <> "" THEN %>
<table width="400" border="0" cellpadding="4" cellspacing="0">
<tr>
<td>
<h3>Search Results:<h3>
</td>
</tr>
<% WHILE NOT RS.EOF AND rowCount < RS.PageSize
rowCount = rowCount + 1
%>
<tr>
<td>
<a href="product.asp?pid=<%=RS( "product_id" )%>">
<%=RS( "product_name" )%></a>
<%=RS( "product_briefDesc" )%>
<a href="product.asp?pid=<%=RS( "product_id" )%>">
get more information</a>
</td>
</tr>
<tr>
<td></td>
</tr>
<%
RS.MoveNext
WEND
%>
<% IF RS.PageCount > 1 THEN %>
<tr>
<td>
Go to page:
<%
FOR i = 1 to RS.PageCount
IF i <> cINT( pg ) THEN
%>
<a href="default.asp?cat=<%=cat%>&pg=<%=i%>">
<%=i%></a>
<% ELSE %>
<%=i%>
<% END IF %>
<% NEXT %>
</font>
</td>
</tr>
<% END IF %>
</table>
<% ELSE %>
<table width="400" border="0" cellpadding="4" cellspacing="0">
<tr>
<td>
<h3>Search Results:h3>
</td>
</tr>
<tr>
<td>No products matched your search
terms.</td>
</tr>
</table>
<% END IF %>
ADODB.Recordset error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/anandatravel/candystore/MPSearch.asp, line 101
I'm using adOpenStatic cursor type because only this supports paging. I suspect that when search term is not blank and cannot be found, EOF is true. Is this the cause of the error? How do I solve this problem? Thanks in advance.
<%
cat = TRIM( Request( "cat" ) )
IF cat = "" THEN cat = "Home"
searchFor = TRIM( Request( "searchFor" ) )
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open(conStr)
%>
<%
' Get the Current Page
pg = TRIM( Request( "pg" ) )
IF pg = "" THEN pg = 1
sqlString = "SELECT product_id, product_name, product_briefDesc " &_
"FROM Products " &_
"WHERE product_status = 1 " &_
"AND ( product_name LIKE '%" & searchFor & "%' " &_
"OR product_briefDesc LIKE '%" & searchFor & "%') " &_
"ORDER BY product_name "
Set RS = Server.CreateObject( "ADODB.Recordset" )
RS.CursorType = adOpenStatic
RS.ActiveConnection = Con
RS.PageSize = 8
RS.Open sqlString
RS.AbsolutePage = pg
%>
<% IF NOT RS.EOF AND searchFor <> "" THEN %>
<table width="400" border="0" cellpadding="4" cellspacing="0">
<tr>
<td>
<h3>Search Results:<h3>
</td>
</tr>
<% WHILE NOT RS.EOF AND rowCount < RS.PageSize
rowCount = rowCount + 1
%>
<tr>
<td>
<a href="product.asp?pid=<%=RS( "product_id" )%>">
<%=RS( "product_name" )%></a>
<%=RS( "product_briefDesc" )%>
<a href="product.asp?pid=<%=RS( "product_id" )%>">
get more information</a>
</td>
</tr>
<tr>
<td></td>
</tr>
<%
RS.MoveNext
WEND
%>
<% IF RS.PageCount > 1 THEN %>
<tr>
<td>
Go to page:
<%
FOR i = 1 to RS.PageCount
IF i <> cINT( pg ) THEN
%>
<a href="default.asp?cat=<%=cat%>&pg=<%=i%>">
<%=i%></a>
<% ELSE %>
<%=i%>
<% END IF %>
<% NEXT %>
</font>
</td>
</tr>
<% END IF %>
</table>
<% ELSE %>
<table width="400" border="0" cellpadding="4" cellspacing="0">
<tr>
<td>
<h3>Search Results:h3>
</td>
</tr>
<tr>
<td>No products matched your search
terms.</td>
</tr>
</table>
<% END IF %>