Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2002
    Thanked 0 Times in 0 Posts

    Error with empty recordset

    Hi! Here am I again...

    I have to do an ASP page that must have 8 combobox.
    I'm doing this way:
    I do a query to my database (SQL Server 7.0) and store it in a recordset. Then I create a combobox and I display the first result, then I do "objrecordset.movenext", create a second combobox and put on it the second result and so on...
    The problem is that, for example, I have 3 results of the query, and when I create the 4º combobox and I do the "objrecordset.movenext" it gives me the "Either BOF or EOF is True.." error.
    I'm doing:
    if (objrecordset.EOF) then
    Response.Write "Empty"
    Response.Write objrecordset("doc")
    end if

    but I still get that error.

    What am I doing wrong????


  • #2
    New Coder
    Join Date
    Jun 2002
    London & Oxford
    Thanked 0 Times in 0 Posts
    First thing to do is think if this really is the best way you can accomplish what you are trying to do. If you need 8 comboboxes on your page yet there is a chance that your script will error I would say it is badly designed in the first place.

    Having said that if there really is no other way, you can check the length of the recordset providing you open it using a non forward-only cursor. By default, when you open a recordset it uses a forward only cursor but you need one that lets you move backwards and forwards (a dynamic cursor) in order to check the length of the recordset.

    When I iterate through a recordset I usually do something like this, maybe it will help you...

    If objRS.EOF Then
    ' there was an error - nothing in the recordset
    Do While Not objRS.EOF
    ' more code here
    End If
    As easy as 3.1415926535897932384626433832795028841

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Thanked 8 Times in 8 Posts
    I don't fully understand what your problem is, but looking at your code, it appears those two lines will cause the error you are receiving. You check to see if your recordset is EOF. If it isn't then you move to the next record before printing out a value.

    If you happen to be on the last record, then use objrecordset.movenext to go to the next record before using response.write to print the value, that should cause your error.

    if (objrecordset.EOF) then 
    Response.Write "Empty" 
    objrecordset.MoveNext 'switch these two lines
    Response.Write objrecordset("doc") 'switch these two lines
    end if


    Posting Permissions

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