How do I use a response if no records are returned?

Results 1 to 5 of 5

Thread: How do I use a response if no records are returned?

  1. #1
    Join Date
    Dec 1969
    Posts
    206

    Default How do I use a response if no records are returned?

    I need to have a message displayed it the sql statement does not turn up any results. How can I go about doing this? If this involves a record count, what is the more speed economic way of counting. I have heard that some counting eats resources. I would appreciate the help.<BR><BR>Brandon

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: How do I use a response if no records are returned?

    There is a recordset property called EOF (stands for End Of File). If EOF is true, then you are at the end of the recordset. When you get your recordset, if it&#039s EOF at the beginning, then you received no records. SO, first thing you should do is test for EOF.<BR><BR>If objRS.EOF then<BR>Response.Redirect "NoRecords.asp"<BR>Else<BR>&#039Show the records<BR>End If<BR><BR>Hope this helps! :)

  3. #3
    Join Date
    Dec 1969
    Posts
    475

    Default RE: How do I use a response if no records are retu

    Where to you input this part of the code? I keep getting&#062; Microsoft VBScript runtime error &#039 800a01a8&#039 <BR>Object required: &#039&#039 <BR><BR>/rets/rets/Customerprofiles/customerprofilereview.asp, line 6 <BR><BR>Thanks<BR> <BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    29

    Default RE: How do I use a response if no records are retu

    You can use the RecordCount property available with RecordSets to check if the recordset has returned data or not. Though EOF is good enough, it can also give errors at times.<BR><BR>Example:<BR>Set Con = Server.CreateObject("ADODB.Connection")<BR>Con.Ope n "FILE NAME = PATH"<BR><BR>You can declare your recordset variable like this:<BR><BR>Set RSet = Server.CreateObject("ADODB.RecordSet")<BR>RSet.Ope n "Select * from TABLENAME", Con, 3, 2<BR><BR>Instead of this:<BR>Set RSet = Con.Execute("Select * from TABLENAME")<BR><BR>You can check the data in the recordset:<BR>if RSet.RecordCount &#060;&#062; 0 then<BR> Response.Write RSet(0)...etc.<BR>else<BR> Response.Write("Data not found")<BR>end if<BR><BR>I hope my answer is reasonably clear.<BR>


  5. #5
    Join Date
    Dec 1969
    Posts
    29

    Default RE: How do I use a response if no records are retu

    You can use the RecordCount property available with RecordSets to check if the recordset has returned data or not. Though EOF is good enough, it can also give errors at times.<BR><BR>Example:<BR>Set Con = Server.CreateObject("ADODB.Connection")<BR>Con.Ope n "FILE NAME = PATH"<BR><BR>You can declare your recordset variable like this:<BR><BR>Set RSet = Server.CreateObject("ADODB.RecordSet")<BR>RSet.Ope n "Select * from TABLENAME", Con, 3, 2<BR><BR>Instead of this:<BR>Set RSet = Con.Execute("Select * from TABLENAME")<BR><BR>You can check the data in the recordset:<BR>if RSet.RecordCount &#060;&#062; 0 then<BR> Response.Write RSet(0)...etc.<BR>else<BR> Response.Write("Data not found")<BR>end if<BR><BR>I hope my answer is reasonably clear.<BR>

Posting Permissions

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