![]() |
Sql - Ado - Values
hallo,
wie ist es, wenn man ne neue zeile bei SQL schreibt? ich habe folgendes gemacht:
Delphi-Quellcode:
Ich habe fehler beim SQL.Text. Ich weisse nicht, ob bei neuer zeilen man die Hochklammer hinfügen soll.
procedure TForm2.Button3Click(Sender: TObject);
begin with adoquery1 do begin sql.Text:= 'Insert Into Tab_Fb_Ziel(paul, simon, alex, jean, rene, alain, simon, dominique, ' 'Raymond, Sylax, jeanne, Yvonne, Claire, Nina, Pierre, Janson, Louis, Lila,' 'maurice )Values (:paul, :simon, :alex, :jean, :rene, :alain, :simon, :dominique, ' ':Raymond, :Sylax, :jeanne, :Yvonne, :Claire, :Nina, :Pierre, :Janson, :Louis, :Lila,' ':maurice )'; Parameters.ParamByName('paul').Value:=Edit1.Text; Parameters.ParamByName('Simon').Value:=Edit2.Text; Parameters.ParamByName('alex').Value:=Edit3.Text; Parameters.ParamByName('jean').Value:=Edit4.Text; Parameters.ParamByName('rene').Value:=Edit5.Text; Parameters.ParamByName('alain').Value:=Edit6.Text; ....... end; end; poter |
Re: Sql - Ado - Values
die erste fehlern habe ich endeckt uzw.:
Delphi-Quellcode:
ich habe die '+' hingefügt aber ab Values geht es nicht mehr
procedure TForm2.Button3Click(Sender: TObject);
begin with adoquery1 do begin sql.Text:= 'Insert Into Tab_Fb_Ziel(paul, simon, alex, jean, rene, alain, simon, dominique, ' + 'Raymond, Sylax, jeanne, Yvonne, Claire, Nina, Pierre, Janson, Louis, Lila,' + 'maurice )Values (:paul, :simon, :alex, :jean, :rene, :alain, :simon, :dominique, ' ':Raymond, :Sylax, :jeanne, :Yvonne, :Claire, :Nina, :Pierre, :Janson, :Louis, :Lila,' ':maurice )'; Parameters.ParamByName('paul').Value:=Edit1.Text; Parameters.ParamByName('Simon').Value:=Edit2.Text; Parameters.ParamByName('alex').Value:=Edit3.Text; Parameters.ParamByName('jean').Value:=Edit4.Text; Parameters.ParamByName('rene').Value:=Edit5.Text; Parameters.ParamByName('alain').Value:=Edit6.Text; ....... end; end; |
Re: Sql - Ado - Values
Bonjour poter,
um einen String aus einzelnen Literalen zusammen zu setzen musst du auch wirklich alle Literale verketten:
Delphi-Quellcode:
Bonne Chance
procedure TForm2.Button3Click(Sender: TObject);
const STMT = 'Insert Into Tab_Fb_Ziel(' + 'paul, simon, alex, jean, rene, alain, simon, dominique, Raymond, Sylax, ' + 'jeanne, Yvonne, Claire, Nina, Pierre, Janson, Louis, Lila, maurice ' + ') Values (' + ':paul, :simon, :alex, :jean, :rene, :alain, :simon, :dominique, :Raymond, :Sylax, ' + ':jeanne, :Yvonne, :Claire, :Nina, :Pierre, :Janson, :Louis, :Lila, :maurice ' + ')' ; begin with adoquery1 do begin // wenn STMT bis auf Parameter statisch ist, // dann genügt einmailiges Zuweisen in FormCreate // oder im Object Inspector und dann muss die Query // nur geschlossen werden: // Close; SQL.Text := STMT; Parameters.ParamByName('paul').Value := Edit1.Text; // ... Open; end; end; |
DP-Maintenance
Dieses Thema wurde von "Matze" von "Windows API / MS.NET Framework API" nach "Datenbanken" verschoben.
Auch wenn es evtl. nur um die Delphi-Grundlagen geht, dem Titel nach gehört das hier hin. |
Re: Sql - Ado - Values
Merci Monsieur,
je vais essayer :-D |
Re: Sql - Ado - Values
Danke, es lauft ganz gut :thumb:
wie kann ich vermeiden, dass ein datensatz 2mal gespeichert wird? bzw eine routine schreiben, die erstmal prüft, ob die identische daten in datenbank vorhanden ist? grüß poter |
Re: Sql - Ado - Values
Oder auf DB-Ebene einen passenden Unique-Index setzen.
|
Re: Sql - Ado - Values
wie ist es praktisch gemeint?
|
Re: Sql - Ado - Values
Du kannst in einer Tabelle ein oder mehrere Felder in Kombination mit einem Unique Index versehen. Dann sorgt das DBMS dafür, dass es nur einen Datensatz mit dem Wert des Feldes oder der Kombination geben darf.
Angenommen, Du hast eine Tabelle mit Benutzern und möchtest sicherstellen, dass die Kombination aus Name und Vorname eindeutig ist. Also legst Du einen Unique Index über diese beiden Felder (Achtung: 1 Index über 2 Felder, nicht jeweils einen!). Dabei ist zu beachten, dass beide Felder möglichst NOT NULL definiert sein sollten. Anschließend führt jeder Versuch, dieselbe Kombination von Namen und Vornamen (z.B. Meier,Heinz) erneut einzufügen, zum Fehler. |
Re: Sql - Ado - Values
wurde es ungefähr so aussehen?
Delphi-Quellcode:
procedure TForm2.Button3Click(Sender: TObject);
begin with adoquery1 do begin CREATE UNIQUE INDEX ID_tabziel ON Tab_Fb_Ziel ('Name,Kunde_nr, datum'); end; end; |
Re: Sql - Ado - Values
Ähm, den SQL (genauer: DDL)-Text würde ich einmalig mit einem Administrationstool auf die DB loslassen.
|
Re: Sql - Ado - Values
ich habe wieder eine frage und zwar ich möchte gern ein DateTimePicker via adoquery in n access db speichern und so sieht das ganze aus:
Delphi-Quellcode:
Ich bekomme eine Fehlermedldung: Ein Parameterobjekt ist nicht ordnunggemäß definiert.
procedure TForm2.Button3Click(Sender: TObject);
var dt: TDateTime; const STMT = 'Insert Into Tab_Fb_Ziel(' + 'paul, simon, alex, jean, rene, alain, simon, dominique, Raymond, Sylax, ' + 'jeanne, Yvonne, Claire, Nina, Pierre, Janson, Louis, Lila, maurice, Jahr ' + ') Values (' + ':paul, :simon, :alex, :jean, :rene, :alain, :simon, :dominique, :Raymond, :Sylax, ' + ':jeanne, :Yvonne, :Claire, :Nina, :Pierre, :Janson, :Louis, :Lila, :maurice, :jahr ' + ')' ; begin with adoquery1 do begin SQL.Text := STMT; dt:= Datetimepicker1.Date; Parameters.ParamByName('paul').Value := Edit1.Text; Parameters.ParamByName('Jahr').Value := dt; // ... ExecSQL; end; end; Dieser Fehler tritt auf seitdem ich das Objekt DateTimePicker1 eingefügt habe. Sieht jemand das Problem? mfg Poter |
Re: Sql - Ado - Values
Wie ist Jahr denn in der DB definiert?
|
Re: Sql - Ado - Values
Jahr ist folgende definiert:
Delphi-Quellcode:
Format: Datum, Kurz zb(09.11.2007)
|
Re: Sql - Ado - Values
Dann würde ich es mal so versuchen:
Delphi-Quellcode:
procedure TForm2.Button3Click(Sender: TObject);
var dt: TDateTime; const STMT = 'Insert Into Tab_Fb_Ziel(' + 'paul, simon, alex, jean, rene, alain, simon, dominique, Raymond, Sylax, ' + 'jeanne, Yvonne, Claire, Nina, Pierre, Janson, Louis, Lila, maurice, Jahr ' + ') Values (' + ':paul, :simon, :alex, :jean, :rene, :alain, :simon, :dominique, :Raymond, :Sylax, ' + ':jeanne, :Yvonne, :Claire, :Nina, :Pierre, :Janson, :Louis, :Lila, :maurice, :jahr ' + ')' ; begin with adoquery1 do begin SQL.Text := STMT; dt:= Datetimepicker1.Date; Parameters.ParamByName('paul').Value := Edit1.Text; Parameters.ParamByName('Jahr').AsDateTime := trunc(dt); // ... ExecSQL; end; end; |
Re: Sql - Ado - Values
Das ist es ja
Delphi-Quellcode:
Ich habe keine möglichkeit, nach
Parameters.ParamByName('Jahr').Value:= dt;
Delphi-Quellcode:
anzugeben. Ich kann alles mögliche wählen aber kein .AsDateTime.
Parameters.ParamByName('Jahr').AsDateTime
|
Re: Sql - Ado - Values
Sorry, mit ADO hab ich keine Erfahrungen. Aber ein Blick in die Hilfe sagt mir, dass das Setzen des Datentyps helfen könnte:
Delphi-Quellcode:
procedure TForm2.Button3Click(Sender: TObject);
var dt: TDateTime; const STMT = 'Insert Into Tab_Fb_Ziel(' + 'paul, simon, alex, jean, rene, alain, simon, dominique, Raymond, Sylax, ' + 'jeanne, Yvonne, Claire, Nina, Pierre, Janson, Louis, Lila, maurice, Jahr ' + ') Values (' + ':paul, :simon, :alex, :jean, :rene, :alain, :simon, :dominique, :Raymond, :Sylax, ' + ':jeanne, :Yvonne, :Claire, :Nina, :Pierre, :Janson, :Louis, :Lila, :maurice, :jahr ' + ')' ; begin with adoquery1 do begin SQL.Text := STMT; dt:= Datetimepicker1.Date; Parameters.ParamByName('paul').Value := Edit1.Text; Parameters.ParamByName('Jahr').DataType := ftDate; Parameters.ParamByName('Jahr').Value := trunc(dt); // ... ExecSQL; end; end; |
Re: Sql - Ado - Values
Klappt leider nicht
|
Re: Sql - Ado - Values
Dieselbe Fehlermeldung?
|
Re: Sql - Ado - Values
sag mal, wie ist deine tabelle eigentlich aufgebaut (welche datentypen haben deine einzelnen felder)... meine kristiallkugel hab ich leider in der firma vergessen...
|
Re: Sql - Ado - Values
ja
|
Re: Sql - Ado - Values
ich habe folgendes:
Delphi-Quellcode:
ID_Name : Autowert (Key)
paul: Text ... maurice: Text .... Jahr:Datum/Uhrzeit (Format: Datum/Kurz) |
Re: Sql - Ado - Values
Und wenn Du den Datentyp auf ftDateTime änderst?
|
Re: Sql - Ado - Values
Moment mal, hast Du auch das trunc eingefügt?
|
Re: Sql - Ado - Values
dann sollte das doch klappen
Delphi-Quellcode:
with adoquery1 do
begin SQL.Text := STMT; dt:= Datetimepicker1.Date; Parameters.ParamByName('paul').Value := Edit1.Text; Parameters.ParamByName('Jahr').value.asDateTime:= dt; oder Parameters.ParamByName('Jahr').value.asDateTime := Datetimepicker1.Date; oder Parameters.ParamByName('Jahr').value := floattostr(Datetimepicker1.Date); Parameters.ParamByName('Jahr').Value := trunc(dt); // ... ExecSQL; end; end; |
Re: Sql - Ado - Values
geht auch nicht
|
Re: Sql - Ado - Values
Zeig nochmal den aktuellen Source.
|
Re: Sql - Ado - Values
du kannst natürlich, statt der parameter spielerei, auch ein ordentliches SQL Statement aufbauen ... :roll: :angel:
|
Re: Sql - Ado - Values
irgendwie klappt es nicht. ich probiere weiter und gebe bescheid
|
Re: Sql - Ado - Values
probier es doch mal so ...
Delphi-Quellcode:
PS: welche datenbank verwendest du eigentlich?
sql.Text:= 'Insert Into Tab_Fb_Ziel(paul, simon, alex, jean, rene, alain, simon, dominique, '
'Raymond, Sylax, jeanne, Yvonne, Claire, Nina, Pierre, Janson, Louis, Lila,' 'maurice, jahr )Values (' + quotedstr(edit1.text) + ', ' + quotedstr(edit2.text) + ', ' + quotedstr(edit3.text) + ', ' + quotedstr(edit4.text) + ', ' + quotedstr(edit5.text) + ', ' + quotedstr(edit6.text) + ', ' + quotedstr(edit7.text) + ', ' + quotedstr(edit8.text) + ', ' + quotedstr(edit9.text) + ', ' + quotedstr(edit10.text) + ', ' + quotedstr(edit11.text) + ', ' + quotedstr(edit12.text) + ', ' + quotedstr(edit13.text) + ', ' + quotedstr(edit14.text) + ', ' + quotedstr(edit15.text) + ', ' + quotedstr(edit16.text) + ', ' + quotedstr(edit17.text) + ', ' + quotedstr(edit18.text) + ', ' + floattostr(dateof(Datetimepicker1.Date)) + ');'; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:00 Uhr. |
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 by Thomas Breitkreuz