Autor Beitrag
PhilSMA
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 26.08.03 09:13 
Hallo zusammen,
"kurze" Frage:
Ich möchte alle Zeilen in einem TDBGrid zählen und ausgeben.
Wie kann ich das am einfachsten anstellen?
Die Daten im Grid kommen von einer StoredProcedure an das ich aber
nicht dran komme. Kann ich vielleicht "einfach" alle Zeilen in diesem DBGrid zählen?
Schreibt bitte eure Antworten für einen Anfänger... :lol:

Danke schonmal,
philsma
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 26.08.03 09:33 
2 Möglichkeiten:

  1. die schlechte:
    ausblenden Delphi-Quelltext
    1:
    2:
    Query1.FetchAll;
    anzahl:=Query1.RecordCount; //anzahl ist integer

  2. die bessere: Du machst es über eine SQL-Abfrage: SELECT count(irgendeinfeld) AS anzahl FROM storedproc(...);Mitanzahl:=Query1.FieldByName('anzahl').AsInteger;bekommst Du dann auch die Anzahl
PhilSMA Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 26.08.03 09:50 
Hmm,
die zweite Variante gefällt mir besser...
Nur:
Könntest Du mir vielleicht eine Schritt-für-Schritt Anlöeitung geben?
Bin in Delphi echt noch neu, und kann mit deiner Antowrt (noch) nicht sooo viel anfangen...

Danke schon mal im Vorraus...
Alfons-G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 307

Win XP Prof, Linux, Win 7
D5 Prof, D7 Architect, D2005 Architect, D2007 Architect
BeitragVerfasst: Di 26.08.03 10:02 
Ich bin zwar nicht UGrohne, aber ...

... er geht bei seiner Antwort davon aus, dass Du als Datenquelle für Deine Abfrage eine TQuery-Komponente verwendest.

Eine Stored Procedure, welche eine Datenmenge zurückliefert, kann man wie eine Tabelle, bzw. einen View abfragen. Deshalb kannst Du eine TQuery-Komponente, hier "Query1" genannt verwenden, um die Anzahl der Datensätze herauszubekommen.
Es sollte allerdingsw sichergestellt sein, dass die Prozedur beim Aufrauf KEINE DATEN VERÄNDERT, sonst könnten unerwartete Nebenwirkungen auftreten. Bei einer Stored Procedure, welche nur Datensätze abfragt, kann es dagegen kein Problem geben.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Query1.SQL.Text := 'SELECT Count (*) AS anzahl FROM storedproc()';
Query1.Open;
intAnzahl := Query1.Fields[0].AsInteger;
Query1.Close;


8)

_________________
Alfons Grünewald
PhilSMA Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mi 27.08.03 10:16 
Sorry dass ich noch mal frage...
so ganz habe ich das leider immer noch nicht verstanden... :(
Wo muss ich den Code von dir einfügen?

Bin leider wirklich blutiger Anfänger...

Gruß,
philSMA