If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
Hi, I have written some ASP code that selects some records from a SQL database according to a criteria, if no information is found in the database then it sees there is an End Of File in the object record set and prints the line below:
<%if objRecordset.EOF then Response.Write("No information was found for the record you have entered") %>
My problem is that if no records are found it still tries to print the information that it is looking for and cannot find and thus throws an exception. The code for that is below:
<Table Border="1" BGCOLOR="white">
<% Response.Write "<TR><TD>The date for that record is " & objRecordset("DateTime") & "<br></TD></TR>" %>
I have tried IF else statements to get around this but im not sure what criteria I should use?
If anyone has any ideas it would be most helpful
Well, you can indeed have "a loop that executes zero times," but it seems to me that you should have an if..then..else structure. If you determine that there are no records, then "that's it." else... print them.
__________________
ChimneySweep(R): fast, automatic
table repair at a click of the
mouse! http://www.sundialservices.com
At the moment i am using an If statement like this:
<%if objRecordset.EOF then Response.Write("No information was found in our databases for the record you have entered") %>
<% Do Until objRecordset.EOF %>
<% Response.Write "<TR><TD>The record that the database has returned is " & objRecordset("TicketNumber") &"</TD></TR>" %>
<% objRecordset.MoveNext %>
<% Loop %>
<%objConn.Close
set objConn=Nothing
%>