![]() |
Datenbank: Absolute Database • Version: 7.1 • Zugriff über: Absolute Database
Counting in a database table
Hello.
I need advice on how to count multiple entries in a database table from the third column to the last column in the whole table. I need to count how many times the table number 1 and 10. I use this code and it is not good:
Delphi-Quellcode:
The result is always the same!
procedure Tfrm_main._NE;
var i,y: integer; begin Application.ProcessMessages; with Table do begin DisableControls; y := 0; try First; while not EOF do begin for I := Table.FieldDefs.Count -1 downto 2 do begin if Pos('1', Table.FieldByName(Table.FieldDefs[i].Name).AsString) > 0 then begin y := y + 1; Label1.Caption := IntToStr(y) + ' x'; Application.ProcessMessages; end; if Pos('10', Table.FieldByName(Table.FieldDefs[i].Name).AsString) > 0 then begin y := y + 1; Label2.Caption := IntToStr(y) + ' x'; Application.ProcessMessages; end; end; Next; Application.ProcessMessages; end; finally EnableControls; Application.ProcessMessages; end; end; |
AW: Counting in a database table
Why do You use same counting variable vor 1 and 10?
Is it intended to double count 1 if there is a 10? Why don't You use a query, to do the count? |
AW: Counting in a database table
Column names are not known in advance.
Now counts correctly. y := 0; y1 := 0; for I := Table.FieldDefs.Count -1 downto 2 do begin if Pos('1', Table.FieldByName(Table.FieldDefs[i].Name).AsString) > 0 then begin y := y + 1; Label1.Caption := IntToStr(y) + ' x'; Application.ProcessMessages; end; if Pos('10', Table.FieldByName(Table.FieldDefs[i].Name).AsString) > 0 then begin y1 := y1 + 1; Label2.Caption := IntToStr(y1) + ' x'; Application.ProcessMessages; end; end; |
AW: Counting in a database table
please give us an example of your data in the Table..
vergisses.. |
AW: Counting in a database table
Liste der Anhänge anzeigen (Anzahl: 1)
OK, here's a picture.
|
AW: Counting in a database table
first it might be better to use Integer-Fields thean String Fields, to avoid double counting.
second all Fields inthe Table should be defined and knowed, so you better use a Query like
Code:
that shoudn't be the fastes way but better than reading thousends of records for a dozend records which really count.
select field1,field2,field3...
frommy mytable where field1=1 or field2=1 or .... or fieldx=10
Delphi-Quellcode:
K-H
procedure Tfrm_main._NE;
var i: integer; cnt1 : integer; cnt10: integer; begin Application.ProcessMessages; with Table do begin DisableControls; cnt1:=0; cnt10:=0; try First; while not EOF do begin for I := Table.FieldDefs.Count -1 downto 2 do begin case Table.FieldByName(Table.FieldDefs[i].Name).AsInteger of 1 : begin cnt1:= cnt1 + 1; Label1.Caption := IntToStr(cnt1) + ' x'; Application.ProcessMessages; end; 10 : begin cnt10 := cnt10 + 1; Label2.Caption := IntToStr(cnt10) + ' x'; Application.ProcessMessages; end; end; Next; Application.ProcessMessages; end; finally EnableControls; Application.ProcessMessages; end; end; |
AW: Counting in a database table
OK.
How then display the result in Label.Caption? |
AW: Counting in a database table
Zitat:
I somehow forgot the Case: :thumb: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:22 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz