Reputation: 2736
My DB Table (Customer) has a field "Active" (YesNo). I'm using TADOTable to work with this table and I would like to have a statistic in the status bar of my app saying how many customers are active and how many are not active. I can always read if my current customer is active by writing this:
bool isActive = CustomerADOTable->FieldByName("Active")->AsBoolean;
but, how to check all records at once? Or do I really need to use TADOQuery and sql statements only because of this?
Upvotes: 1
Views: 783
Reputation: 13367
You're either going to have to run a query, or loop through all records in the table and keep a count of how many have Active set to true.
The query is going to be significantly faster, unless you've got very few records. And the query is the right way(tm) to do it. It'll scale much better.
Upvotes: 2
Reputation: 27385
To avoid looping and an own query, you might use the Filter property.
begin
Showmessage(IntToStr(DS.RecordCount));
DS.Filter := 'Active=true';
DS.Filtered := true;
Showmessage(IntToStr(DS.RecordCount));
DS.Filtered := false;
end;
Upvotes: 1