Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Newbie Question: Database test for no records
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

seahorse
Senior Member

USA
1075 Posts

Posted - 26 April 2002 :  01:56:57  Show Profile  Visit seahorse's Homepage
Hi Everybody,

I've got a question regarding a test for no records. I found this on one of the aspin.com tutorials

if rsTest.BOF = fales and reTest.EOF = false
then
...


Is this essentially the same as:

if rsTest.recordcount = 0 
then
...


if not, what's the difference?



Ken

===============
The greatest tragedy is a child without a loving parent.

Nathan
Help Moderator

USA
7664 Posts

Posted - 26 April 2002 :  02:00:56  Show Profile  Visit Nathan's Homepage
Humm.

I would use this

if rsTest.BOF OR rsTest.EOF then
'is empty
end if


Probably have less problems with database compatablility using this method.

Nathan Bales
Snitz Exchange | Do's and Dont's
Go to Top of Page

@tomic
Senior Member

USA
1790 Posts

Posted - 26 April 2002 :  02:04:02  Show Profile  Visit @tomic's Homepage  Send @tomic an ICQ Message
I was thinking of Nathan's solution when I first read this. It's still what makes sense to me though I wait with anticipation the post that shows me the error of my ways...

@tomic

http://www.skepticfriends.org
Go to Top of Page

seahorse
Senior Member

USA
1075 Posts

Posted - 26 April 2002 :  03:34:30  Show Profile  Visit seahorse's Homepage
quote:

if rsTest.recordcount = 0 then...




I tried this with a query I knew had O results and it tells me that the number of records is -1. I have no idea why.


Ken

===============
The greatest tragedy is a child without a loving parent.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 26 April 2002 :  05:39:07  Show Profile  Send ruirib a Yahoo! Message
quote:

quote:

if rsTest.recordcount = 0 then...




I tried this with a query I knew had O results and it tells me that the number of records is -1. I have no idea why.


Ken

===============
The greatest tragedy is a child without a loving parent.


That depends on the cursor type specified for your recordset. Quoting from MSDN:


The RecordCount property depends on the capabilities of the provider and the type of cursor. The RecordCount property will return -1 for a forward-only cursor, the actual count for a static or keyset cursor, and either -1 or the actual count for a dynamic cursor, depending on the data source.

In certain cases, your provider or cursor might be unable to provide the RecordCount value without first fetching all records from the data source. To force this type of fetch, call the Recordset MoveLast method before calling RecordCount.


To set the cursor type these are the values:

Keyset: rs.CursorType = 1
Dynamic: rs.CursorType = 2
Static: rs.CursorType = 3


-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 26 April 2002 :  12:27:20  Show Profile
You should test your recordset immediately after you create it.

I always use If rs.bof = true and rs.eof = true to determine an empty recordset.

You can usually shortcut to If rs.eof = true

ADO will position the cursor to the first record if there are records present, so neither .bof or .eof will be true if something is there.

As ruirib pointed out, don't depend on recordcount unless you're sure that you will get reliable results.



======
Doug G
======
Go to Top of Page

work mule
Senior Member

USA
1358 Posts

Posted - 26 April 2002 :  14:34:55  Show Profile
The "official" docs

Recordset Object (ADO)
http://msdn.microsoft.com/library/en-us/ado270/htm/mdobjodbrec.asp

Properties, Methods, Events
http://msdn.microsoft.com/library/en-us/ado270/htm/mdobjodbrecpme.asp

Go to Top of Page

seahorse
Senior Member

USA
1075 Posts

Posted - 30 April 2002 :  22:44:39  Show Profile  Visit seahorse's Homepage
Thanks Everybody,

All of your comments have been really helpful.


Ken

===============
The greatest tragedy is a child without a loving parent.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.43 seconds. Powered By: Snitz Forums 2000 Version 3.4.07