Solved

Counting records

Posted on 2002-07-06
7
154 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
ID: 7134294
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
ID: 7134295
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
ID: 7134303
CrazyOne,

I haven't used SQL much. How do I get the query into my code?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 44

Expert Comment

by:CrazyOne
ID: 7134384
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
ID: 7135031
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
ID: 7135032
sorry,

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

Expert Comment

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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