Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2004
    Location
    UK
    Posts
    15

    Question Unanswered: ASP returning SQL data help

    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

  2. #2
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Hello,

    Could you send all your asp code concerning this matter, please ? It will help !

    Regards,

    RBARAER

  3. #3
    Join Date
    Sep 2004
    Location
    UK
    Posts
    15
    I got it sorted using a "Do Until statement" thanks anyway.

  4. #4
    Join Date
    Oct 2003
    Posts
    706
    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

  5. #5
    Join Date
    Sep 2004
    Location
    UK
    Posts
    15
    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
    %>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •