Autor Beitrag
LickstheComp
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 17.04.09 13:28 
Ich möchte zu einem bestimmten Datensatz andere Daten dazuspeichern. Aber es kommt immer das ein Semikolon fehlt. .

ausblenden Delphi-Quelltext
1:
ADOquery4.sql.add('Insert INTO Tabelle1 (User) VALUES ("'+combobox1.Text+'") SELECT * FROM Tabelle1 WHERE (LNR=10) ;');					


Die Nummer von LNR ist egal, die mach ich dan noch dynamisch.

lg
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Fr 17.04.09 13:40 
Was auch immer du mit dem Select.. bezweckst ..
du schreibst 2 Sql-Befehle in eins - das geht nicht

Insert into .. () values (); <-- fertig bei schreiben ohne bedingung

oder (was ich eher vermute, du willst bedingt schreiben )

insert into .. () values () where xy = Select ...

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
LickstheComp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 17.04.09 13:56 
ja mit bedingung, also so:
Insert INTO Tabelle1 (User) VALUES ("'+combobox1.Text+'") WHERE (LNR=10) ?
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 17.04.09 14:02 
user profile iconLickstheComp hat folgendes geschrieben Zum zitierten Posting springen:
ja mit bedingung, also so:
Insert INTO Tabelle1 (User) VALUES ("'+combobox1.Text+'") WHERE (LNR=10) ?

Ja, so ungefähr muss es aussehen. Wobei Du aber ein Problem bekommst, wenn in combox1.Text ein " oder ein ; vorkommt.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
LickstheComp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 17.04.09 14:08 
Trotzdem kommt das ein Semikolon fehlt :(
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 17.04.09 14:12 
Was steht denn in Combobox1.Text?

Schau Dir das zusammengebastelte Statement mal an: ShowMessage(ADOquery4.sql.GetText) und poste ggf. hier.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Fr 17.04.09 14:18 
Äh.. was bitte soll ein INSERT mit einem WHERE?
Insert fügt einen Datensatz hinzu - wofür soll man da noch eine Bedingung angeben?

Kann es sein, dass ihr das mit UPDATE verwechselt?

_________________
PROGRAMMER: A device for converting coffee into software.
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 17.04.09 14:19 
user profile iconXentar hat folgendes geschrieben Zum zitierten Posting springen:
Äh.. was bitte soll ein INSERT mit einem WHERE?
Insert fügt einen Datensatz hinzu - wofür soll man da noch eine Bedingung angeben?

Kann es sein, dass ihr das mit UPDATE verwechselt?

:autsch: :autsch:
Womit Du natürlich vollkommen recht hast! Naja, man merkt, dass es Freitag ist.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
LickstheComp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 17.04.09 14:21 
also statt insert into einfach update schreiben?
firool
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Fr 17.04.09 14:24 
Hi,

mach zusätzlich aus dem:

VALUES ("'+combobox1.Text+'") SELECT
ein
VALUES ('''+combobox1.Text+''') SELECT

Also 3 einzelne Hochkommas.

Gruß
firool

_________________
--
keine SIG
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 17.04.09 14:25 
user profile iconLickstheComp hat folgendes geschrieben Zum zitierten Posting springen:
also statt insert into einfach update schreiben?

Da ist die Frage, was Du willst.

Möchtest Du einen NEUEN Datensatz einfügen:
ausblenden SQL-Anweisung
1:
Insert into tabelle (feld1, feld2) VALUES (wert1, wert2)					


Möchtest Du einen BESTEHENDEN Datensatz ändern:
ausblenden SQL-Anweisung
1:
Update tabelle set feld1=wert1,feld2=wert2 where bedingung					

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)


Zuletzt bearbeitet von Nersgatt am Fr 17.04.09 14:26, insgesamt 1-mal bearbeitet
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Fr 17.04.09 14:25 
Die Zeile muss entweder so lauten :
ausblenden Delphi-Quelltext
1:
ADOquery4.sql.add('Insert INTO Tabelle1 (User) VALUES (' + QuotedStr(combobox1.text) + ') ;');					

oder so :
ausblenden Delphi-Quelltext
1:
ADOquery4.sql.add('UPDATE Tabelle1 SET User =' + QuotedStr(combobox1.text) + ') WHERE LNR=10;');					
LickstheComp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 17.04.09 14:30 
Danke die Zeile von bis11 funktioniert!
was bedeutet QuotedStr ?
lg


p.s. kann man statt ' + QuotedStr(combobox1.text) + ' nicht was anderes schreiben?


Zuletzt bearbeitet von LickstheComp am Fr 17.04.09 14:32, insgesamt 1-mal bearbeitet
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 17.04.09 14:31 
user profile iconLickstheComp hat folgendes geschrieben Zum zitierten Posting springen:

was bedeutet QuotedStr ?
lg

Einfach mal den Cursor draufstellen und F1 drücken.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
LickstheComp Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 17.04.09 14:33 
ok danke habs!!
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 17.04.09 15:10 
Ich würde aber SQL-Parameter verwenden, dann bist Du auch vor SQL-Injection geschützt.