Win32 Com + ADO: How to compare the result of a recordset to 'nothing'

Graham Breed usenet at
Mon Sep 15 21:36:26 CEST 2003

logistix at wrote:

> Recordsets have a .BOF property that is similar to .EOF, but indicates
> that your cursor is before the first record.  If both .BOF and .EOF
> are true, you have a null recordset.  So something like:
> if not(rst.BOF and rst.EOF):
>     rst.MoveFirst()
> should work.

Maybe should, but frequently doesn't.  Although the books tell you to do 
this, I've never found it to be any use.  SQL Server, at any rate, 
always sets the cursor to the first record, so rst.EOF is enough to test 
for no records.  The problem comes when nothing is returned, which is 
different to no records being returned.  (In Query Analyser, you see 
nothing, instead of column names with nothing underneath.)  In that 
case, I find checking for rst.State==1 does the trick.  I think BOF 
fails the same way as EOF in this case (if the record set's closed, it's 
an error to even ask where the cursor is).

 From the error message, I don't think this is the OP's problem, though. 
  You would see something telling you not to do that on a closed record 
set.  I suggest poking the object in an interpreter, and looking in 
pywintypes, if nobody has any better ideas.


More information about the Python-list mailing list