Einzelnen Beitrag anzeigen

Benutzerbild von p80286
p80286

Registriert seit: 28. Apr 2008
Ort: Stolberg (Rhl)
6.659 Beiträge
 
FreePascal / Lazarus
 
#6

AW: Counting in a database table

  Alt 30. Nov 2012, 11:07
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:
select field1,field2,field3...
frommy mytable
where field1=1
  or field2=1
  or ....
  or fieldx=10
that shoudn't be the fastes way but better than reading thousends of records for a dozend records which really count.

Delphi-Quellcode:
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;
K-H
Programme gehorchen nicht Deinen Absichten sondern Deinen Anweisungen
R.E.D retired error detector

Geändert von p80286 (30. Nov 2012 um 11:13 Uhr)
  Mit Zitat antworten Zitat