Solved

Counting records

Posted on 2002-07-06
7
153 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 99
Delphi: how to implement a User Shortcut mapper? 1 93
Delphi selector screen 2 69
how can i search if string exist in array ? 3 49
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

930 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

12 Experts available now in Live!

Get 1:1 Help Now