Autor Beitrag
Anuschka
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Windows XP Home
Delphi 5 Standard
BeitragVerfasst: Di 07.12.04 14:51 
Hi,

ich bin auf ein Problem gestossen beim INSERT INTO mit Delphi. Ich möchte gerne dass er die ID automatisch hochzählt ohne dass ich eine Zahl eingebe.

Ich weiss dass ich wenn ich mit PHP arbeite einfach nur heisst:

ausblenden Quelltext
1:
 $sql = "INSERT INTO user VALUES ('*', '$Nachname', '$Vorname', '$Passwort', '$Email')";					


Aber wenn ich mit Delphi arbeite funktioniert das nicht wirklich. Er gibt mir immer eine Fehlermeldung bei dem *.
Ausdruck erwartet aber '*' gefunden.

ausblenden Quelltext
1:
tmp:='INSERT INTO `pc` VALUES ' + ' (' + #39 + * +  #39 +' )					


Wenn ich es mit
ausblenden Quelltext
1:
tmp:='INSERT INTO `pc` VALUES ' + ' (' + #39 + '*' +  #39 +' )					

probiere schreibt er mit ein * in die DB.
weiss einer von euch eine Lösung?
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 07.12.04 14:53 
Hallo!

Was für eine DB nutzt du? Schon NULL als Wert für das Feld probiert?

Cu,
Udontknow
Anuschka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Windows XP Home
Delphi 5 Standard
BeitragVerfasst: Di 07.12.04 15:26 
ich nutze:
MySQL 4.0.21

ja NULL Hab ich auch schon probiert aber da sagt er mir beim zweiten eintrag dass er schon nen eintrag damit da hat.
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Di 07.12.04 15:52 
Hallo,

das Feld muss mit dem Attribut AUTO_INCREMENT versehen sein, dann wird eine automatisch hochgezählte ID in das Feld geschrieben, wenn man NULL angibt.

Stefan
Anuschka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Windows XP Home
Delphi 5 Standard
BeitragVerfasst: Di 07.12.04 15:58 
hi

danke nur dass hab ich leider auch schon. das ID Feld ist auto_increment und auch der primärschlüssel

daran kann es nicht liegen
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 07.12.04 16:03 
hmmm...

Hast du Auto_Increment nach dem Einfügen des "NULL"-Datensatzes deklariert?

Wenn ja, lösch mal den Eintrag, der den Primary Key "NULL" hat.

Cu,
Udontknow
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 07.12.04 16:28 
Las das Feld in Deinem Insert doch einfach weg, wenn es ein AutoIncrement ist:
ausblenden Delphi-Quelltext
1:
"INSERT INTO user (nachname, vorname, passwort, email) VALUES ('$Nachname''$Vorname''$Passwort''$Email')";					

Es ist sowieso immer eine gute Idee bei einem INSERT alle Felder anzugeben, die befüllt werden sollen, auch wenn es alle sind. Denn ansonsten kann es Dir um die Ohren fliegen, wenn später mal ein Feld dazukommt.
Anuschka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Windows XP Home
Delphi 5 Standard
BeitragVerfasst: Di 07.12.04 16:35 
danke dass werd ich machen, hab es nur weggelassen da ich ja eh alle felder nehme und damit dann der quelltext noch mehr anschwillt.

aber danke nochmal

hoffe es geht damit