Delphi-PRAXiS
Seite 3 von 4     123 4      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi wie schreibe ich daten in eine paradox7 tabelle? (https://www.delphipraxis.net/17740-wie-schreibe-ich-daten-eine-paradox7-tabelle.html)

libFelix.so 9. Mär 2004 12:16

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
Delphi-Quellcode:
Sql.Add('Insert into "' + StrTable + '" (Ort + ', ' + Datum + ', ' + Name + ', ' + Bahn1 + ', ' + Bahn1Ab + ', ' + Bahn1Drops + ', ' + Bahn2 + ', ' + Bahn2Ab + ', ' + Bahn2Drops + ', ' + Bahn3 + ', ' + Bahn3Ab + ', ' + Bahn3Drops + ', ' + Bahn4 + ', ' + Bahn4Ab + ', ' + Bahn4Drops + ', ' + GesDrops + ', ' + GesSL + ', ' + GesGT + ', ' + GesEL + ', ' + Gesamt + ') values (' + ComboBox2.Items.Strings[ComboBox2.ItemIndex] + ', ' + {DATUM} + ', ' + ComboBox1.Items.Strings[ComboBox1.ItemIndex] + ', ' + IntToStr(wupb1) + ', ' + IntToStr(wupb1ab) + ', ' + IntToStr(wupb1d) + ', ' + IntToStr(wupb2) + ', ' + IntToStr(wupb2ab) + ', ' + IntToStr(wupb2d) + ', ' + IntToStr(wupb3) + ', ' + IntToStr(wupb3ab) + ', ' + IntToStr(wupb3d) + ', ' + IntToStr(wupb4) + ', ' + IntToStr(wupb4ab) + ', ' + IntToStr(wupb4d) + ', ' + IntToStr(wupgesd) + ', ' + {GesSL} + ', ' + {GesGT} + ', ' + {GesEL} + ', ' + IntToStr(wupges) + ')');
mal NUR der insert befehl

Cuchulainn 9. Mär 2004 12:19

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
Versuch es mal damit:

Delphi-Quellcode:
Sql.Add('Insert into "' + StrTable + '" (Ort , Datum , Name, Bahn1, Bahn1Ab, Bahn1Drops, Bahn2,
'Bahn2Ab, Bahn2Drops, Bahn3, Bahn3Ab, Bahn3Drops, Bahn4, Bahn4Ab, Bahn4Drops, GesDrops, GesSL, GesGT, GesEL, Gesamt) values ('
+ ComboBox2.Items.Strings[ComboBox2.ItemIndex] + ', ' + DATUM + ', ' +
ComboBox1.Items.Strings[ComboBox1.ItemIndex] + ', ' + IntToStr(wupb1) + ', ' +
wupb1ab + ', ' + IntToStr(wupb1d) + ', ' + IntToStr(wupb2) + ', ' + wupb2ab + ', ' +
 IntToStr(wupb2d) + ', ' + IntToStr(wupb3) + ', ' + wupb3ab + ', ' + IntToStr(wupb3d) + ', ' +
 IntToStr(wupb4) + ', ' + wupb4ab + ', ' + IntToStr(wupb4d) + ', ' + IntToStr(wupgesd) + ', ' + GesSL
 + ', ' + ', ' + GesGT + ', ' + ', ' + GesEL + ', ' + IntToStr(wupges) + ')');

Robert_G 9. Mär 2004 12:21

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
Moin :hi:

Habt ihr beide schon mal was von Code-formatierung gehört?
Hättest du dein SQL-Statement besser formatiert (bei der Spaltenanzahl ein Muss!!!), hättest du zum Bleistift ein paar doppelte "," bemerkt.

Warum eigentlich das?
Delphi-Quellcode:
...'Ort ', ' + Datum + ', ' + Name + ', ...
So ist es doch viel einfacher (und es funktioniert :wink: ) :
Delphi-Quellcode:
...'Ort, Datum, Name ...
Ich habe mal schnell deinen Code etwas umformatiert.
Da ich ein paar Stellen geändert habe, kann es sein, dass er von dir korrigiert werden muss.
Delphi-Quellcode:
  With Query1 Do
  Begin
    SQL.Text :=
      'Insert INTO ' + StrTable + #10 +
      ' (Ort' + #10 +
      ' ,Datum' + #10 +
      ' ,Name' + #10 +
      ' ,Bahn1' + #10 +
      ' ,Bahn1Ab' + #10 +
      ' ,Bahn1Drops' + #10 +
      ' ,Bahn2' + #10 +
      ' ,Bahn2Ab' + #10 +
      ' ,Bahn2Drops' + #10 +
      ' ,Bahn3' + #10 +
      ' ,Bahn3Ab' + #10 +
      ' ,Bahn3Drops' + #10 +
      ' ,Bahn4' + #10 +
      ' ,Bahn4Ab' + #10 +
      ' ,Bahn4Drops' + #10 +
      ' ,GesDrops' + #10 +
      ' ,GesSL' + #10 +
      ' ,GesGT' + #10 +
      ' ,GesEL' + #10 +
      ' ,Gesamt)' + #10 +
      'VALUES' + #10 +
      ' (:i_Ort' + #10 +
      ' ,:i_Datum' + #10 +
      ' ,:i_Name' + #10 +
      ' ,:i_Bahn1' + #10 +
      ' ,:i_Bahn1Ab' + #10 +
      ' ,:i_Bahn1Drops' + #10 +
      ' ,:i_Bahn2' + #10 +
      ' ,:i_Bahn2Ab' + #10 +
      ' ,:i_Bahn2Drops' + #10 +
      ' ,:i_Bahn3' + #10 +
      ' ,:i_Bahn3Ab' + #10 +
      ' ,:i_Bahn3Drops' + #10 +
      ' ,:i_Bahn4' + #10 +
      ' ,:i_Bahn4Ab' + #10 +
      ' ,:i_Bahn4Drops' + #10 +
      ' ,:i_GesDrops' + #10 +
      ' ,:i_GesSL' + #10 +
      ' ,:i_GesGT' + #10 +
      ' ,:i_GesEL' + #10 +
      ' ,:i_Gesamt)';
    Prepared := True;
    With Params Do
    Begin
      ParamByName('i_Ort')      .AsString  := ORT;
      // Ich nahm an, dass DATUM in der Tabelle ein Datumsfeld ist
      ParamByName('i_DATUM')    .AsDateTime := DATUM ;
      ParamByName('i_NAME')     .AsString  := NAME ;
      ParamByName('i_Bahn1')    .AsInteger := wupb1;
      ParamByName('i_Bahn1Ab')  .AsString  := wupb1ab;
      ParamByName('i_Bahn1Drops').AsInteger := wupb1d;
      ParamByName('i_Bahn2')    .AsInteger := wupb2;
      ParamByName('i_Bahn2Ab')  .AsString  := wupb2ab;
      ParamByName('i_Bahn2Drops').AsInteger := wupb2d;
      ParamByName('i_Bahn3')    .AsInteger := wupb3;
      ParamByName('i_Bahn3Ab')  .AsString  := wupb3ab;
      ParamByName('i_Bahn3Drops').AsInteger := wupb3d;
      ParamByName('i_Bahn4')    .AsInteger := wupb4;
      ParamByName('i_Bahn4Ab')  .AsString  := wupb4ab;
      ParamByName('i_Bahn4Drops').AsInteger := wupb4d;
      ParamByName('i_GesDrops') .AsInteger := wupgesd;
      ParamByName('i_GesSL')    .AsString  := GesSL;
      ParamByName('i_GesGT')    .AsString  := GesGT;
      ParamByName('i_GesEL')    .AsString  := GesEL;
      ParamByName('i_Gesamt')   .AsInteger := wupges;
    End;
    ExecSQL;
  End;
Edit: Ein Haufen Tippfehler und Doppelpunkte in der Parameterzuweisung...
Edit 573 ( :mrgreen: ) : Noch ein Doppelpunkt

libFelix.so 9. Mär 2004 12:25

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
Code:
[Fehler] Unit1.pas(150): ')' erwartet, aber Bezeichner 'ComboBox2' gefunden
sagt der mir nun... man is das kagge....


kann ich di das project mal schicken???

libFelix.so 9. Mär 2004 12:27

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
thx robert. ich probier es gleich mal aus und ja, bei dem feld datum soll das datum rein, das der user dan auswählt

libFelix.so 9. Mär 2004 12:37

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
also ich kann das programm nun endlich wieder starten, aber es trägt nix in die db ein.
wenn ich mir die mit dem tool dboberfläche anzeige, stehen da keine einträge.

Cuchulainn 9. Mär 2004 13:02

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
Wie sieht denn dein Quelltext jetzt aus?

libFelix.so 9. Mär 2004 13:06

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, DB, DBTables, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    DBRadioGroup1: TDBRadioGroup;
    DBRadioGroup2: TDBRadioGroup;
    DBRadioGroup3: TDBRadioGroup;
    DBRadioGroup4: TDBRadioGroup;
    Query1: TQuery;
    DateTimePicker1: TDateTimePicker;
    Label12: TLabel;
    Label13: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);


  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Query1: TQuery;
  datum, wupb1, wupb2, wupb3, wupb4, wupb1d, wupb2d, wupb3d, wupb4d, wupb1ab, wupb2ab, wupb3ab, wupb4ab, wupgesd, wupsl, wupgt, wupel, wupges: integer;
  ort, name: string[50];

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin

  //Einlesen der Variablen
  wupb1 := StrToInt(Edit2.Text);
  wupb2 := StrToInt(Edit3.Text);
  wupb3 := StrToInt(Edit4.Text);
  wupb4 := StrToInt(Edit5.Text);
  wupb1d := StrToInt (Edit7.Text);
  wupb2d := StrToInt (Edit8.Text);
  wupb3d := StrToInt (Edit9.Text);
  wupb4d := StrToInt (Edit10.Text);

  //Abzüge pro Bahn
  //Bahn1
  case DBRadioGroup1.ItemIndex of
    0 : wupb1 := wupb1 - 1;
    1 : wupb1 := wupb1 - 2;
    2 : wupb1 := wupb1 - 5;
  end;
  //Bahn2
  case DBRadioGroup2.ItemIndex of
    0 : wupb2 := wupb2 - 1;
    1 : wupb2 := wupb2 - 2;
    2 : wupb2 := wupb2 - 5;
  end;
  //Bahn3
  case DBRadioGroup3.ItemIndex of
    0 : wupb3 := wupb3 - 1;
    1 : wupb3 := wupb3 - 2;
    2 : wupb3 := wupb3 - 5;
  end;
  //Bahn4
  case DBRadioGroup4.ItemIndex of
    0 : wupb4 := wupb4 - 1;
    1 : wupb4 := wupb4 - 2;
    2 : wupb4 := wupb4 - 5;
  end;

  //Drops pro Bahn incl. Zuzüge
  wupb1 := (wupb1d * 2) + wupb1;
  wupb2 := (wupb2d * 2) + wupb2;
  wupb3 := (wupb3d * 2) + wupb3;
  wupb4 := (wupb4d * 2) + wupb4;

  //GesamtDrops
  wupgesd := wupb1d + wupb2d + wupb3d + wupb4d;

  //GesamtSchläge incl. Abzüge
  wupges := wupb1 + wupb2 + wupb3 + wupb4;

  //Ausgabe - Gesamt Drops
  Edit11.Text := IntToStr(wupgesd);

  //Ausgabe - Gesamt Schläge incl. Zu-/Abzüge
  Edit6.Text := IntToStr(wupges);

  name := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
  ort := ComboBox2.Items.Strings[ComboBox2.ItemIndex];
  wupb1ab := 1;
  wupb2ab := 1;
  wupb3ab := 1;
  wupb4ab := 1;
  wupsl := 1;
  wupel := 1;
  wupgt := 1;
  datum := 1;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  f :textfile;

begin
  //In Datei schreiben
  AssignFile(f,'erg_wup.txt');
    {$i-}
      Append(f);
    {$i+}
    if IOResult <> 0 then halt;
      Writeln(f,ComboBox2.Items.Strings[ComboBox2.ItemIndex] + ',' + ComboBox1.Items.Strings[ComboBox1.ItemIndex] + ',' + Edit2.Text + ',' + Edit7.Text + ',' + Edit3.Text + ',' + Edit8.Text + ',' + Edit4.Text + ',' + Edit9.Text + ',' + Edit5.Text + ',' + Edit10.Text + ',' + Edit6.Text + ',' + Edit11.Text);
    CloseFile(f)

end;

procedure PEinlesen;
var
  StrTable: String;

begin
  StrTable := ExtractFilePath(ParamStr(0)) + 'db/db.db';
  // Datensätze mit Query einfügen
  With Query1 Do
  Begin
    SQL.Text :=
      'Insert INTO ' + StrTable + #10 +
      ' (Ort' + #10 +
      ' ,Datum' + #10 +
      ' ,Name' + #10 +
      ' ,Bahn1' + #10 +
      ' ,Bahn1Ab' + #10 +
      ' ,Bahn1Drops' + #10 +
      ' ,Bahn2' + #10 +
      ' ,Bahn2Ab' + #10 +
      ' ,Bahn2Drops' + #10 +
      ' ,Bahn3' + #10 +
      ' ,Bahn3Ab' + #10 +
      ' ,Bahn3Drops' + #10 +
      ' ,Bahn4' + #10 +
      ' ,Bahn4Ab' + #10 +
      ' ,Bahn4Drops' + #10 +
      ' ,GesDrops' + #10 +
      ' ,GesSL' + #10 +
      ' ,GesGT' + #10 +
      ' ,GesEL' + #10 +
      ' ,Gesamt)' + #10 +
      'VALUES' + #10 +
      ' (:i_Ort' + #10 +
      ' ,:i_Datum' + #10 +
      ' ,:i_Name' + #10 +
      ' ,:i_Bahn1' + #10 +
      ' ,:i_Bahn1Ab' + #10 +
      ' ,:i_Bahn1Drops' + #10 +
      ' ,:i_Bahn2' + #10 +
      ' ,:i_Bahn2Ab' + #10 +
      ' ,:i_Bahn2Drops' + #10 +
      ' ,:i_Bahn3' + #10 +
      ' ,:i_Bahn3Ab' + #10 +
      ' ,:i_Bahn3Drops' + #10 +
      ' ,:i_Bahn4' + #10 +
      ' ,:i_Bahn4Ab' + #10 +
      ' ,:i_Bahn4Drops' + #10 +
      ' ,:i_GesDrops' + #10 +
      ' ,:i_GesSL' + #10 +
      ' ,:i_GesGT' + #10 +
      ' ,:i_GesEL' + #10 +
      ' ,:i_Gesamt)';
    Prepared := True;
    With Params Do
    Begin
      ParamByName(':i_Ort')      .AsString  := ort;
      // Ich nahm an, dass DATUM in der Tabelle ein Datumsfeld ist
      ParamByName(':i_DATUM')    .AsInteger := datum;
      ParamByName(':i_NAME')     .AsString  := name;
      ParamByName(':i_Bahn1')    .AsInteger := wupb1;
      ParamByName(':i_Bahn1Ab')  .AsInteger := wupb1ab;
      ParamByName(':i_Bahn1Drops').AsInteger := wupb1d;
      ParamByName(':i_Bahn2')    .AsInteger := wupb2;
      ParamByName(':i_Bahn2Ab')  .AsInteger := wupb2ab;
      ParamByName(':i_Bahn2Drops').AsInteger := wupb2d;
      ParamByName(':i_Bahn3')    .AsInteger := wupb3;
      ParamByName(':i_Bahn3Ab')  .AsInteger := wupb3ab;
      ParamByName(':i_Bahn3Drops').AsInteger := wupb3d;
      ParamByName(':i_Bahn4')    .AsInteger := wupb4;
      ParamByName(':i_Bahn4Ab')  .AsInteger := wupb4ab;
      ParamByName(':i_Bahn4Drops').AsInteger := wupb4d;
      ParamByName(':i_GesDrops') .AsInteger := wupgesd;
      ParamByName(':i_GesSL')    .AsInteger := wupsl;
      ParamByName(':i_GesGT')    .AsInteger := wupgt;
      ParamByName(':i_GesEL')    .AsInteger := wupel;
      ParamByName(':i_Gesamt')   .AsInteger := wupges;
    End;
    ExecSQL;
  End;
end;
end.
ist nun e erstmal der code....
sieht schiick aus, ist mit aber ehrlichgesagt zu lang.... aber dafür funzt es

Cuchulainn 9. Mär 2004 13:08

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
Du musst die Prozedur PEinlesen auch aufrufen. Sonst geschieht natürlich nichts :)

libFelix.so 9. Mär 2004 13:23

Re: wie schreibe ich daten in eine paradox7 tabelle?
 
oops wie peinlich :oops: :wall: :roll:

aber er gibt mir trotzdem ne fehlermeldung ca so:

ungültiges schlüsselwort
system-string: ?
zeilennummer: 1


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:49 Uhr.
Seite 3 von 4     123 4      

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-2025 by Thomas Breitkreuz