Autor Beitrag
Ivy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mo 24.01.11 09:46 
Hallo zusammen,
ich bin gerade dabei ein formular zu erstellen, wo der benutzer daten eingeben kann un diese in einer mysql datenbank gespeichert werden. Nun hab ich das problem, dass er mir mit der INSERT INTO anweisung irgendwie nichts einträgt.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
command.CommandText = "INSERT INTO daten VALUES" + "('" + txtName.Text + "', '" +
                                                                txtFabrikat.Text + "', '" +
                                                               txtKlirrfaktor.Text + "', '" +
                                                             txtRMS.Text + "', '" +
                                                            txtSN.Text + "', '" +
                                                            txtFrequenz.Text + "');";


das ist meine anweisung.ich weiß nicht was ich falsch gemacht habe... beim debuggen erscheint die anweisung ganz normal?!
also INSERT INTO daten VALUES('a','b','c');
lg ivy
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Mo 24.01.11 10:31 
Was für eine Fehlermeldung kommt denn?

Und ein Insert-Befehl sieht so aus:
ausblenden Quelltext
1:
2:
INSERT INTO "Tabellen_Name" ("Spalte1", "Spalte2", ...)
VALUES ("Wert1", "Wert2", ...)
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mo 24.01.11 10:39 
hey,
ich habs rausbekommen, ich hab einfach nach der anweisung:
ausblenden C#-Quelltext
1:
2:
Console.WriteLine("INSERT, Total rows affected:" + 
                            MyCommand.ExecuteNonQuery());;


gehängt dann ging es aufeinmal. total komisch^^
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4799
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 24.01.11 13:39 
Hallo Ivy,

schau dir unbedingt mal die Programmierung mittels SQL-Parametern an, s. meinen Link unter www.c-sharp-forum.de....php?p=619527#619527

Das manuelle Zusammenbauen von SQL-Befehlen mittels Stringkonkatenierung erzeugt evtl. Fehler (z.B. wenn das Hochkomma selber im Text vorkommt) und v.a. ist ein Angriffsziel für SQL-Injection!!!