开发者

Why does recordset.RecordCount equal 1 but recordset.EOF and recordset.BOF both equal True

I have a very simple query that only returns one record. When I try to get the value out of the only column in the only record, I get "Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record." What's going on here? The code that is causing the error doesn't even execute if RecordCount is 0 and I have verified that the recordset does in fact conta开发者_StackOverflow中文版in a record.

Code is below. Error is thrown when trying to set strDN. It's so dead simple but I can't figure out where I'm going wrong.

EDITED TO INCLUDE COMMAND

<LDAP://DC=something,DC=com>;(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(employeeID=01234567));distinguishedName;subtree

Set adoRecordset = adoCommand.Execute


    If adoRecordset.RecordCount > 0 Then


        strDN = adoRecordset.Fields("distinguishedName").Value

        Set objUser = GetObject("LDAP://" & strDN)

        objGroup.add(objUser.ADsPath)

    End if


The recordcount property leaves the cursor at the end of the recordset, so you cannot then obtain the record (eof=true), you must movefirst. Use a different cursor type, because the default cursor type is forward only:

'' Assign cursorType that allows forward and backward movement.
adoRecordset.cursorType = 3 ''adOpenStatic

See https://www.w3schools.com/asp/prop_rs_cursortype.asp


I use

If Not adoRecordset.EOF And Not adoRecordset.BOF Then
...
End If

For This Scenario


Try

Set adoRecordset = adoCommand.Execute    

    If adoRecordset.RecordCount > 0 Then

        adoRecordset.MoveFirst 'Move to the first record

        strDN = adoRecordset.Fields("distinguishedName").Value

        Set objUser = GetObject("LDAP://" & strDN)

        objGroup.add(objUser.ADsPath)

    End if


-EDIT- Have a look at the following link. There are some causes listed, and solutions for most of them:

http://classicasp.aspfaq.com/general/why-do-i-get-bof-or-eof-errors.html

[I was wrong about this - thanks, Dave] I believe you need to call adoRecordset.MoveNext (or whatever the call is) before attempting to get the value of a field in the recordset.


Calling adoRecordSet.Requery() after RecordCount request can also help in this situation, if your query isn't that complex to execute it the second time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜