Author |
Topic |
|
seahorse
Senior Member
USA
1075 Posts |
Posted - 26 April 2002 : 01:56:57
|
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
|
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 |
|
|
@tomic
Senior Member
USA
1790 Posts |
Posted - 26 April 2002 : 02:04:02
|
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 |
|
|
seahorse
Senior Member
USA
1075 Posts |
Posted - 26 April 2002 : 03:34:30
|
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. |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 26 April 2002 : 05:39:07
|
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 |
|
|
Doug G
Support Moderator
USA
6493 Posts |
Posted - 26 April 2002 : 12:27:20
|
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 ====== |
|
|
work mule
Senior Member
USA
1358 Posts |
|
seahorse
Senior Member
USA
1075 Posts |
Posted - 30 April 2002 : 22:44:39
|
Thanks Everybody,
All of your comments have been really helpful.
Ken
=============== The greatest tragedy is a child without a loving parent. |
|
|
|
Topic |
|