Board index » delphi » Use of the recordcount method in ADODataSet?

Use of the recordcount method in ADODataSet?


2004-08-06 03:54:57 AM
delphi252
Is using the recordcount method in ADODataSet the preferred method for
getting a count of the records that have been returned from the commandtext
statement in situations where you need a record count?
I remember that using this was discouraged and not recommended for BDE and
other database systems because it wasn't acurate and it placed a large
processing burden on the database server. Still rather new to ADO so not
sure how this works compared to other non-SQL database systems.
BTW I am familiar with the 'select count *' SQL command but not how to use
it in conjunction with a ADODataset that needs to also feed a database
display grid (an example). Also how do you get the results from a 'select
count *' statement for use as a variable in your program?
An example of my commandtext statement without count:
select * from Personnel order by PERS_USERID
Regards;
Bob Dalton
 
 

Re:Use of the recordcount method in ADODataSet?

Bob,
If you say "select count(*) as numrecs from myTable where myColumn='xxx'",
then you get access to it with
rcount := myTable.fieldbyname('numrecs').asfloat;
Yes, reccount is accurate in ado datasets that return results.
 

Re:Use of the recordcount method in ADODataSet?

Thanks to all who replied for the information!
Regards;
Bob Dalton
 

Re:Use of the recordcount method in ADODataSet?

I tried this in my ADODataSetComponent:
select count(*) as numrecs from Personnel order by PERS_USERID
When the active property is set to true I get the following error:
"Column name "Personnel.PERS_USERID is invalid in the ORDER BY clause
because it is not contained in an aggregate fucntion and there is no GROUP
BY clause."
Not having used this type statement before I am not sure exactly how to fix
the problem and I need the ORDER BY part of the query.
Regards;
Bob Dalton
"Del Murray" <XXXX@XXXXX.COM>writes
Quote
Bob,
If you say "select count(*) as numrecs from myTable where myColumn='xxx'",
then you get access to it with

rcount := myTable.fieldbyname('numrecs').asfloat;

Yes, reccount is accurate in ado datasets that return results.


 

Re:Use of the recordcount method in ADODataSet?

Why would you care about the order if the only thing returning is the number
of records? Remove the order by statement.
"Bob Dalton" <XXXX@XXXXX.COM>writes
Quote
I tried this in my ADODataSetComponent:

select count(*) as numrecs from Personnel order by PERS_USERID

When the active property is set to true I get the following error:

"Column name "Personnel.PERS_USERID is invalid in the ORDER BY clause
because it is not contained in an aggregate fucntion and there is no GROUP
BY clause."

Not having used this type statement before I am not sure exactly how to
fix
the problem and I need the ORDER BY part of the query.

Regards;

Bob Dalton

"Del Murray" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Bob,
>If you say "select count(*) as numrecs from myTable where
myColumn='xxx'",
>then you get access to it with
>
>rcount := myTable.fieldbyname('numrecs').asfloat;
>
>Yes, reccount is accurate in ado datasets that return results.
>
>