Solved

Counting records

Posted on 2002-07-06
7
152 Views
Last Modified: 2012-05-04
Hi all,

I have a DBCtrlGrid connected to an ADO table. It shows a list of customer names. Beside each name, I have a check-box (fieldname is SELECTED).
As I select each customer, I would like to be able to see how many I have selected.

I know I can use ADOTable.Recordcount to count ALL records, but how can I count only the ones with SELECTED=True?

Thanks,
Freerider.
0
Comment
Question by:Freerider
  • 3
  • 3
7 Comments
 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
You could use a query

SELECT Count(TheField) AS CountOfField
FROM TheTable
WHERE TheField = True;


The Crazy One
0
 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
If the database does not fully support boolean expersions in the WHERE clause you could do this

WHERE TheField <> 0;
0
 

Author Comment

by:Freerider
Comment Utility
CrazyOne,

I haven't used SQL much. How do I get the query into my code?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
Well one way is to drop an ADO query on the form. And then double click on the SQL property and then add the SQL statement there. Activate the query componenet like you do the table component.
0
 
LVL 1

Accepted Solution

by:
chengjian earned 100 total points
Comment Utility
function CountRecord(AConnection:TADOConnection):Integer;
var
 aq:TADOQuery;
begin
 Result := -1;
 aq := TADOQuery.Create;
 try
  aq.Connection := AConnection;
  aq.sql.Add('SELECT COUNT(FieldName) FROM YourTable WHERE TheField = TRUE');
  aq.ExecSQL;
  Result := aq.Fields[0].AsInteger;
 finally
  aq.free;
 end;
end;
0
 
LVL 1

Expert Comment

by:chengjian
Comment Utility
sorry,

> aq.ExecSQL;
Should be aq.Open;
0
 
LVL 1

Expert Comment

by:chengjian
Comment Utility
The paramenterAConnection is the TADOConnection component you have used in your program, ADOConnection1 for example.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now