Results 1 to 12 of 12

Thread: EOF is making problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    pakistan
    Posts
    14

    EOF is making problem

    i m trying to pick data randomly from the data base
    but an error is getting generate the error is:
    "either EOF or BOF is true or the current record has been deleted; the operation requested by the application requires a current record."
    the record is available in th data base
    de is the "data environment", "cid" is a variable having class id, "sid" is a variable having subject id from the tables.
    plz c the code below 'n send me the answer.


    While Not de.rscmd3.EOF
    k = CInt(Rnd * 10)
    de.rscmd3.Filter = "classid= " & cid & " And subjectid = " & sid & " And questionid = " & k
    If de.rscmd3.EOF = True Then
    de.rscmd3.MoveFirst
    End If
    paper.List1.AddItem "Q:" & x & ") " & de.rscmd3.Fields("question")
    x = x + 1
    If x = no Then
    paper.Show
    de.rscmd3.Close
    Exit Sub
    End If
    Wend

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    If de.rscmd3.EOF = True Then
    --------------------------------------
    This usualy indicates that recordset is empty.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by IROY55
    If de.rscmd3.EOF = True Then
    --------------------------------------
    This usualy indicates that recordset is empty.
    Not quite 100% correct .EOF only indicates the end of the recordset.

    if (.EOF AND .BOF ) is true, then you have an empty recordset.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    No, when EOF is True means (in most of the time) that there is no records returned from the DB.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by IROY55
    No, when EOF is True means (in most of the time) that there is no records returned from the DB.
    Yes... BUT the problem is that he's checking for EOF, if EOF is True (which in the case of an empty recordset it is), he's doing a .MoveFirst.... which he can't do, because BOF is also true.
    Here's how I would do it:
    VB Code:
    1. de.rscmd3.Filter = "classid= " & cid & " And subjectid = " & sid & " And questionid = " & k
    2. If NOT (de.rscmd3.EOF AND de.rscmd3.BOF) Then
    3. de.rscmd3.MoveFirst
    4. End If
    But that's just one gnome's opinon.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Yes... BUT the problem is that he's checking for EOF, if EOF is True (which in the case of an empty recordset it is), he's doing a .MoveFirst.... which he can't do, because BOF is also true.
    The very simple answer is:
    VB Code:
    1. If Rs.EOF = True Then
    2.     MsgBox "No Data Found"
    3. End If
    Roy

  7. #7
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101
    Originally posted by IROY55
    VB Code:
    1. If Rs.EOF = True Then
    2.     MsgBox "No Data Found"
    3. End If
    Yo, I'm sorry, but that's a pretty reckless way of going about it. Like Tech, I disagree.

    Here's the definite solution, that I would use (and it's still pretty simple):

    VB Code:
    1. If DB.BOF And DB.EOF Then
    2. MsgBox "The database is empty"
    3. Else
    4. DB.MoveFirst
    5. End If

    All you need to do is include both BOF and EOF, using the operator as shown. Simple.
    Last edited by trojjer; Sep 20th, 2002 at 05:28 PM.
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  8. #8
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Hey YOOOOOOOOOOO, I have a name first.
    Second,
    I can give you a lecture if you need on this topic. But the easiest way to explain this to you would be the following:
    DB compiler (if you will) first "sets" itself on the BOF of the future return set and then must "populate" the space between BOF and EOF. But if there is no records to get based on the query it "moves" immediately to the EOF and pointer will stay there. So in your program all you need to do is to whether or not EOF = True.
    Is that clear now, yoooo.

    Best regards, Roy

  9. #9
    Lively Member
    Join Date
    Jul 2002
    Location
    Gateshead, UK
    Posts
    101

    Maybe so...

    ...Yeah, ok IROY(55?) - that would probably work. I'm just saying that, to remove any doubt, adding that little conditional statement for BOF will not do any harm.

    I know you are a non-conformist on this issue (I am, usually...); so fine... I would stick to the proven - and simple - methods for this, though.
    <% Session("OwNeD")=True %><html><body>Blah... <%="Now get your ass back to the twilight zone..."%></body></html>

  10. #10
    Hyperactive Member crosbj's Avatar
    Join Date
    Oct 2000
    Location
    Michigan
    Posts
    285
    Just wanted to add the following from the MSDN.
    If you open a Recordset object containing no records, the BOF and EOF properties are set to True, and the Recordset object's RecordCount property setting is zero. When you open a Recordset object that contains at least one record, the first record is the current record and the BOF and EOF properties are False.

    If you delete the last remaining record in the Recordset object, the BOF and EOF properties may remain False until you attempt to reposition the current record.
    I bring it up for the second paragraph that mentions deleting records. I have gotten errors moving through ado recordset's when users deleted the last record because both .BOF and .EOF are false but there are no records? I started to use the recordcount instead of .BOF and .EOF. I know its off the post but it is an odd quirk about ADO to be aware of. (not sure about ado.net)

  11. #11
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Assuming you're running with ADO it is ALWAYS better to use .RecordCount (as long as the ODBC engine you're tied to supports it, I know MySQL doesn't but Access and SQL server do, so YMMV)

    This is because RecordCount ALWAYS returns the current status of the recordset without tossing an error, like a .MoveNext and .EOF check might do.

    It is also very sloppy coding to only check .EOF at the beginning of a DB query. It's better to use something like this:

    If Not (recset.eof And recset.bof) Then
    Do
    recset.movenext
    Loop until Recset.eof
    End If


    Of course this may vary depending on the situation.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  12. #12
    Hyperactive Member crosbj's Avatar
    Join Date
    Oct 2000
    Location
    Michigan
    Posts
    285
    Assuming you're running with ADO it is ALWAYS better to use .RecordCount
    Thanks 'mlewis' I always wondered if I should be using the .RecordCount for various ADO recordset functions but it seemed to be the only way I could avoid certain errors. Just wasn't sure if it was proper to rely on it so much.

Posting Permissions

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



Click Here to Expand Forum to Full Width