Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Counting records

Posted on 2002-07-06
7
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 400 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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