PDA

Click to See Complete Forum and Search --> : How can I know if a database is empty?


willye
Mar 26th, 2000, 10:34 PM
The recordcount property doesn't work. I have values different from 0 even if the database is empty. And if I use .BOF I have an error!

Thanks

pardede
Mar 27th, 2000, 03:44 AM
have you tried checking .eof ?

Jaguar
Mar 27th, 2000, 06:10 AM
I have tried so many times to try and use .RecordCount for a recordset and it just is not consistent. I am assuming you are using ADO, but if not, it doesn't matter; same concept applies.

Soo.... I have changed to doing a count of the records that would be returned with a regular recordset first, because it is very fast, and if I don't have to hit the database to get the big load of stuff, if I don't have to then, alrgight.

What I'm saying is this... (Yes you may hit the DB twice), but it may be worth it.
"ssql = "Select Count(ID) From Names Where State = 'CA'"
Use some field name that is in your table to simply get the number of records in the recordset. Don't use the Count(*) method because then it has to search the Fields collection of the database and examine all the fields. Then, use this
if ors.Fields(1) > 0 then
ssql = Select ID, Last, First from Names Where State = 'CA'
ors.open ssql, oConn, adforwardonly
...
end if
This will tell you how many records you have by, 1) not having to do a .MoveLast and open you RS in a non-forwardonly fashion, 2) it lets you make a decision.

Hope the info helps for something.