Autor Beitrag
Morpheus1572
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157

Win XP
Delphi 7
BeitragVerfasst: Sa 07.03.09 14:38 
Moin,

was ich hier gefunden habe will bei mir nicht klappen. nun frage ich also mal sportlich in die Runde: Wo ist mein F...Gedankenfehler?

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:
  If x > 0 then
    begin
      While x > i do
      begin
      i:=i+1;
      y:=IntToStr(i);
      ADOQuery1.Close;
      ADOQuery1.SQL.Clear;
      ADOQuery1.Active:=false;

      ADOQuery1.SQL.Text:='SELECT Tour.Tour, Sammeltour.AGTID, Sammeltour.TID '+
        'FROM Sammeltour INNER JOIN Tour ON Sammeltour.TID = Tour.TID ' +
        'WHERE (((Sammeltour.AGTID)<1)AND Sammeltour.TID = :tourid)';

//      ADOQuery1.Parameters.ParamByName('tourid').DataType:=ftInteger;
      ADOQuery1.Parameters.ParamByName('tourid').Value:=y;
      ADOQuery1.Prepared := true;
      ADOQuery1.Active:=true;
      ds := DataSource1.DataSet;
      Tour := ds['Tour'];
      CheckListBox1.Items.Add(Tour);
//      CheckListBox1.Sorted:=true;


wenn ich das hier - für mich richtige - abschicke, dann bekomme ich einen Fehler das der Typ Null nicht in String umgewandelt werden konnte...

Sammeltour.TID ist in der Tabelle eine Zahl und da liegt mein Problem denke ich...

Kann jemand helfen?

Thx Morph.

edit: lasse ich den parameter weg funzt es zumindest soweit, dass ich keine fehlermeldung bekomme...
Sinspin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1338
Erhaltene Danke: 120

Win 10
RIO, CE, Lazarus
BeitragVerfasst: Sa 07.03.09 14:54 
Ich vermute tourid ist ein Integer. Also solltest du die überflüssige Umwandlung in String weglassen und bei der Zuweisung direkt den Integer übergeben.
Das geht einmal auf die Variante "Value" oder über eines der "As" Properties. Im Fall von Integer ist es dann "AsInteger".

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:
  If x > 0 then
    begin
      While x > i do
      begin
      i:=i+1;
      //y:=IntToStr(i);
      ADOQuery1.Close;
      ADOQuery1.SQL.Clear;
      ADOQuery1.Active:=false;

      ADOQuery1.SQL.Text:='SELECT Tour.Tour, Sammeltour.AGTID, Sammeltour.TID '+
        'FROM Sammeltour INNER JOIN Tour ON Sammeltour.TID = Tour.TID ' +
        'WHERE (((Sammeltour.AGTID)<1)AND Sammeltour.TID = :tourid)';

//      ADOQuery1.Parameters.ParamByName('tourid').DataType:=ftInteger;
      //ADOQuery1.Parameters.ParamByName('tourid').Value:=y;
      ADOQuery1.Parameters.ParamByName('tourid').Value:=i;  // <---- so ...
      ADOQuery1.Parameters.ParamByName('tourid').AsInteger:=y; // <----- oder so.
      ADOQuery1.Prepared := true;
      ADOQuery1.Active:=true;
      ds := DataSource1.DataSet;
      Tour := ds['Tour'];
      CheckListBox1.Items.Add(Tour);
//      CheckListBox1.Sorted:=true;

_________________
Wir zerstören die Natur und Wälder der Erde. Wir töten wilde Tiere für Trophäen. Wir produzieren Lebewesen als Massenware um sie nach wenigen Monaten zu töten. Warum sollte unser aller Mutter, die Natur, nicht die gleichen Rechte haben?
Robert.Wachtel
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 895
Erhaltene Danke: 7

Windows 7 Ultimate x64
D5 Ent, D7 Arch, RAD Studio 2010 Pro, VS 2008
BeitragVerfasst: Sa 07.03.09 15:10 
Mal abgesehen davon, dass im Originalquelltext viel redundanter Code enthalten ist, halte ich es zumindest aus Performancegründen auch nicht für sinnvoll, in einer Schleife für jeden Wert eine eigene Datenbankabfrage durchzuführen.

Schon mal daran gedacht, mit einer Abfrage alle gefragten Werte abzufragen und dann das zurückgelieferte Resultset durchzuarbeiten?

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:
  // einmalig zur Initialisierung
  MyQuery.SQL.Text := 'SELECT Tour.Tour, Sammeltour.AGTID, Sammeltour.TID' +
    ' FROM Sammeltour INNER JOIN Tour ON Sammeltour.TID = Tour.TID' +
    ' WHERE Sammeltour.AGTID < 1 AND Sammeltour.TID > :tourIdVon' +
    ' AND Sammeltour.TID <= :tourBisId';
  MyQuery.Prepared := true;

  // [...]

  // eigentliche Abfrage
  if x > 0 and x > i do
  begin
      MyQuery.Close;
      MyQuery.Parameters.ParamByName('tourIdVon').AsInteger := x;
      MyQuery.Parameters.ParamByName('tourIdBis').AsInteger := i;
      MyQuery.Open;
      while not MyQuery.Eof() do
      begin
        CheckListBox1.Items.Add(MyQuery.FieldByName('Tour').AsString);
        MyQuery.Next;
      end;
  end;
Bernhard Geyer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 721
Erhaltene Danke: 3



BeitragVerfasst: Sa 07.03.09 15:22 
Dein Preparing ist vollkommen an der falschen Stelle. Ich bau mal etwas um ...

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:
  if x > 0 then
  begin
    ADOQuery1.Close;
    ADOQuery1.SQL.Text:='SELECT Tour.Tour, Sammeltour.AGTID, Sammeltour.TID '+
      'FROM Sammeltour INNER JOIN Tour ON Sammeltour.TID = Tour.TID ' +
      'WHERE (((Sammeltour.AGTID)<1)AND Sammeltour.TID = :tourid)';

    ds := DataSource1.DataSet;

    ADOQuery1.Prepared := true;

    While x > i do
    begin
      Inc(i);
      ADOQuery1.Parameters.ParamByName('tourid').Value:= IntToStr(i);
      ADOQuery1.Active:=true;
      Tour := ds['Tour'];
      CheckListBox1.Items.Add(Tour);
    end;

    ADOQuery1.Prepared := false;
  end;


Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt
Morpheus1572 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157

Win XP
Delphi 7
BeitragVerfasst: Sa 07.03.09 15:40 
Das ging schnell... ;-)

Welche variante ich auch durchspiele gibt es immer das gleich ergebnis. ABER:

irgendwie tritt der fehler bei der tourenzuordnung des ds auf.

ausblenden Delphi-Quelltext
1:
2:
      ds := DataSource1.DataSet;
      Tour := ds['Tour'];


@Robert.Wachtel:

Vielen Dank für die aufzeigung meiner Fehler. ich bin noch nciht sooo lange delphianer und freu mich über solche anregungen.

aber dennoch funzt mein problem noch nicht.

Was bei mir auch nen fehler bringt ist die zeile, in der ich den paramater mit .asinteger zuweisen soll. das gibt ne fehlermeldung...!

Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt
Bernhard Geyer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 721
Erhaltene Danke: 3



BeitragVerfasst: Sa 07.03.09 15:50 
user profile iconMorpheus1572 hat folgendes geschrieben Zum zitierten Posting springen:
irgendwie tritt der fehler bei der tourenzuordnung des ds auf.

ds := DataSource1.DataSet;
Tour := ds['Tour'];

Ist der Feldwert hier NULL? Falls Ja: As Designed.
Nimm mal

ausblenden Delphi-Quelltext
1:
  Tour := ds.FieldByName('Tour').AsString					


In der AsString-Methode wird genau dieser Fall abgefangen indem ein Leerstring zurückgeliefert wird.
Morpheus1572 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157

Win XP
Delphi 7
BeitragVerfasst: Sa 07.03.09 15:59 
er kam, sah und fand meine inkompetenz: Bernhard Geyer!

Thx. nu klappt es mit dem darstellen. bishauf, dass ich nun 2 leere CheckBoxen habe weil die entsprechenden touren ausgeblendet werden. aber das bekomme ich hoffentlich noch hin.

Großes THX an alle!