Database Results Page

S

Stu

I'm using this code display results based on a number
entered into a form.

<%
ID = Request.QueryString( "ID")
if ID ="" then ID ="1"

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=C:mypath\mydatabase.mdb"

quote = "SELECT * FROM Results Where ID = "& ID &""
Set quote = Conn.Execute( quote)

if quote.eof then
Response.write("No records found.")
end if

%>

It works fine, but when you do a seach and there is no
record, you get this error message:

No records Found

ADODB.Field error '80020009'

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

/quote/test2view/testview.asp, line 0

How do I get rid of the error message and have it only
say "No records found"?
 
T

Thomas A. Rowe

Try the following format. I rarely use Response.Write to write to the browser, unless to see the
what is being passed to the Query, so you will notice use tables:


<%
ID = Request.QueryString("ID")
if ID ="" then ID ="1"

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:mypath\mydatabase.mdb"

quote = "SELECT * FROM Results Where ID = "& ID &""
Set quote = Conn.Execute( quote)
%>
<html>
<head>
<title>
</title>
</head>

<body>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<% If quote.eof Then %>
<tr>
<td>Sorry, No Records Found!</td>
</tr>
<% Else %>
<tr>
<td>DISPLAY FOUND RECORDS HERE</td>
</tr>
<% End If %>
</table>
</body>
</html>

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top