Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 01.04.11 08:57 
Hi, Delpher,

ich will eine Geburtstagsabfrage über zwei Tabellen machen. Die Ergebnisse sollen in einem Stringgrid untereinander erscheinen.
Dazwischen soll eine Leerzeile stehen.

Etwas code habe ich schon:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
procedure TBuchMain.GebTagAlle(sender:Tobject);
var tbname  : string;
    qx      : TQuery;
    r, c, k, nk   : integer;
begin
  for r := 1 to tntstringgrid1.rowcount-1 do
    for c := 1 to tntstringgrid1.ColCount-1 do
      tntstringgrid1.cells[c,r] := '';
  tntstringgrid1.ColCount := 4;

  qx := TQuery.create(Application);            // neu dazu geschrieben
  qx.datasource := qSchueler.DataSource;
  tbname := TbSchueler.TableName;

  qx.Close;
    if qx.FindField('gebdat') <> NIL then
      qx.SQL.Text := format('select Name, Vorname, Klasse from "%s" ', [TbName]);
  qx.Open;
  tntstringgrid1.RowCount := qx.recordcount+1;
  tntstringgrid1.RowHeights[0] := 20;
  tntstringgrid1.cells[0,0] := 'Nr';
  //for nk := 1 to qx.FieldCount do
    //tntstringgrid1.Cells[nk,0] := qx.Fields[nk-1].DisplayName;

  qx.First;  k := 0;
  while not qx.eof do
  begin
    with tntstringgrid1 do
    begin
      inc(k); cells[0,k] := inttostr(k);
//       for nk := 1 to qx.FieldCount do cells[nk,k] := qx.Fields[nk-1].asstring;
      for nk := 1 to qx.FieldCount do
        cells[nk,k] := qx.Fields[nk-1].asstring;
      end;
    end;
    qx.next;
  end;
  {if k > 0 then
  begin
    Gridbreite(tntstringgrid1, groupbox2.Width-Splitter2.MinSize);
    checkbox11.Checked := true; checkbox11click(self);
  end;}
   // else tntstringgrid1.RowCount := 2;
  //anz_DS := qx.RecordCount+1;

  // 1 LZ SG?


  qx.datasource := qLk.DataSource;              // hier Fehler: Deklaration erwartet,
  tbname := TbLk.Tablename;                     //         aber Bezeichner qx gefunden

  qx.Close;
    if qx.FindField('gebdat') <> NIL then
      qx.SQL.Text := format('select Name, Vorname, Klasse from "%s" ', [TbName]);
  qx.Open;

  qx.First;  k := 0;
  while not qx.eof do
  begin
    with tntstringgrid1 do
    begin
      inc(k); cells[0,k] := inttostr(k);
//       for nk := 1 to qx.FieldCount do cells[nk,k] := qx.Fields[nk-1].asstring;
      for nk := 1 to qx.FieldCount do
        cells[nk,k] := qx.Fields[nk-1].asstring;
      end;
    end;
    qx.next;
  end;

end;


Muss ich eine Query-Komponente auf das Formular legen?

Jetzt habe ich bei der Ausführung die Fehlermeldung:
"Keine SQL-Anweisung verfügbar"

Danke für Hilfe,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas


Zuletzt bearbeitet von D. Annies am Fr 01.04.11 09:34, insgesamt 1-mal bearbeitet
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Fr 01.04.11 09:21 
user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:
Hi, Delpher,

ich will eine Geburtstagsabfrage über zwei Tabellen machen. Die Ergebnisse sollen in einem Stringgrid untereinander erscheinen.
Dazwischen soll eine Leerzeile stehen.

Etwas code habe ich schon:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
...

  qx.First;  k := 0;
  while not qx.eof do
  begin
    with tntstringgrid1 do
    begin
      inc(k); cells[0,k] := inttostr(k);
//       for nk := 1 to qx.FieldCount do cells[nk,k] := qx.Fields[nk-1].asstring;
      for nk := 1 to qx.FieldCount do
        cells[nk,k] := qx.Fields[nk-1].asstring;
      end;  // Dieses END gehört NICHT zur Schleife
    end;
    qx.next;
  end;  // Dieses END beendet die Methode
  {if k > 0 then
  begin
    Gridbreite(tntstringgrid1, groupbox2.Width-Splitter2.MinSize);
    checkbox11.Checked := true; checkbox11click(self);
  end;}
   // else tntstringgrid1.RowCount := 2;
  //anz_DS := qx.RecordCount+1;

  // 1 LZ SG?


  qx.datasource := qLk.DataSource;              // hier Fehler: Deklaration erwartet,
  tbname := TbLk.Tablename;                     //         aber Bezeichner qx gefunden

  ...




Hi,
durch eine richtige Einrückung hättest du den Fehler sofort gefunden :-)

Das oben markierte End schliesst nicht um die Schleife.
Somit beendet das nächste markierte End die Methode.
Was danach kommt kann entsprechend nicht mehr auf die lokalen Variablen zugreifen.

_________________
Delphi: XE - OS: Windows 7 Professional x64
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 01.04.11 09:27 
Danke Stefan, habe ich eben auch gesehen. (So viel mal wieder zu CopyAndPaste)
Mal sehen, ob es so auch auch funzt!

Jetzt habe ich bei der Ausführung die Fehlermeldung:
"Keine SQL-Anweisung verfügbar"

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Fr 01.04.11 10:44 
Wupps?

Ich musste schon zur Entwurfszeit einen Sql-String vergeben, das war's
Detlef

_________________
ut vires desint, tamen est laudanda voluntas