[VB] Syntaxfehler in UPDATE-Anweisung

rgunt

Aktives Mitglied
Hallo zusammen!
Ich habe folgendes Problem:

Ich möchte ein Programm schreiben (VB) mit dem ich auf Datenbanken zugreifen kann. Das hab ich schon mal gemacht, und da hats prächtig funktioniert...

Bei diesem Programm entsteht an der folgenden Stelle im Code (markiert mit -->) den unten aufgeführten Fehler:

Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim anzahl As Integer

'Try
con.Open()

cmd.CommandText = "update saldo set Konto-Nr = '" & txtKontoNr.Text() & "', Klient = '" & txtKlient.Text() & _
"', Saldo = '" & txtSaldo.Text() & "' where ObjNr = " & pnummer(ListBox1.SelectedIndex)

--> MsgBox(cmd.CommandText)

anzahl = cmd.ExecuteNonQuery()

If anzahl > 0 Then
MsgBox("Eintrag erfolgreich geändert", MsgBoxStyle.Information, "Ändern erfolgreich")
End If

' Catch ex As Exception
' MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler beim Ändern")
' End Try
con.Close()
AlleSehen()
End Sub


Fehler:
System.Data.OleDb.OleDbException wurde nicht behandelt.
ErrorCode=-2147217900
Message=Syntaxfehler in UPDATE-Anweisung.
Source=Microsoft JET Database Engine
StackTrace:
bei System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
bei System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
bei System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
bei System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
bei System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
bei System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
bei BankManager.Saldo.Button2_Click(Object sender, EventArgs e) in C:\Users\Raphael\Documents\Visual Studio 2008\Projects\BankManager\BankManager\BankingManagementCompontents\Saldo\Saldo.vb:Zeile 79.
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bei BankManager.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
InnerException:

Sollte jemand wissen, was ich falsch gemacht habe, oder wie ich das Problem beheben kann, soll er sich bitte umgehend bei mir melden!

P.S. Den Code aus dem alten Projekt kopieren geht nicht! Hab ich schon probiert!
 

pagefault

Inaktiv
Wie sind denn die Felddefinitionen der Saldo-Tabelle?
Könnte es sein, dass du ein Datentyp-Problem hast? (z.B. Text in ein Number-Feld abfüllen o.ä.)
 

LMS

Stammgast
cmd.CommandText = "update saldo set Konto-Nr = '" & txtKontoNr.Text() & "', Klient = '" & txtKlient.Text() & _
"', Saldo = '" & txtSaldo.Text() & "' where ObjNr = " & pnummer(ListBox1.SelectedIndex)

...
Message=Syntaxfehler in UPDATE-Anweisung.

Attributname mit Bindestrich? Bist du sicher dass das geht?

Melde dich bitte umgehend, wenn dir dieser Hinweis etwas weiterhilft.
 

rgunt

Aktives Mitglied
Änderung (nicht UPDATE sondern INSERT)

Ich habe das Projekt mit der Bank verworfen, aber ich habe es mit einer DVD-Datenbank fortgeführt.
Hier der neue Code: (ACHTUNG, ES IST EINE INSERT-ANWEISUNG)

Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
Dim anzahl As Integer
If txtNummer.Text = "" Then
MsgBox("Bitte eine Discnummer eintragen!")
Exit Sub
End If

Try
con.Open()
cmd.CommandText = "insert into dvd " & _
"(nr, titel, usk / fsk,) " & _
"values ('" & _
txtNummer.Text & "', '" & _
txtTitel.Text & "', " & _
txtFSK.Text & "')"
'MsgBox(cmd.CommandText)
anzahl = cmd.ExecuteNonQuery()
If anzahl > 0 Then
MsgBox("Es wurde ein Datensatz eingefügt")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()

AlleSehen()
End Sub

Der Fehler blieb der selbe.

P.S. Falls Sie es wünschen, gebe ich Ihnen die Projektdatei und die Datenbank.
 

pagefault

Inaktiv
...
cmd.CommandText = "insert into dvd " & _
"(nr, titel, usk / fsk,) " & _
"values ('" & _
txtNummer.Text & "', '" & _
txtTitel.Text & "', " & _
txtFSK.Text & "')"
Ich kann mich nur wiederholen: Wie sind die Felddefinitionen?

Bei diesem Insert sehe ich z.B., dass in das Feld "nr" ein Text-String abgefüllt werden soll.

Sollte das Feld "nr" tatsächlich vom Typ Number (oder Integer o.ä.) sein, kann bereits ein . oder Komma (je nach selektiertem Dezimaltrennzeichen) in der Eingabe einen Fehler triggern.
 

rgunt

Aktives Mitglied
AW

Die Tabellenspalten der Tabelle "dvd" in der Datenbank sind:

nr
titel
usk / fsk

Alle Spalten sind auf Datentyp "Text" eingestellt.

P.S. Das Einlesen funktioniert nach wie vor reibungslos.
 

rgunt

Aktives Mitglied
Thema beendet

Ich hab rausgekriegt, warum es nicht funzt!
Das Datenbankenformat war auf Office 2003, vb.net liest (warum auch immer) nur Office 2000-Datenbanken
 
Oben