Nach Abfrage erhalte ich eine Fehlermeldung

  • VB.NET
  • .NET (FX) 4.0

Es gibt 25 Antworten in diesem Thema. Der letzte Beitrag () ist von petaod.

    Nach Abfrage erhalte ich eine Fehlermeldung

    Hallo,

    nachdem ich den Button zur Abfrage betätige, kommt folgende Fehlermeldung:

    Spoiler anzeigen
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Key WHERE Keys LIKE '1' at Line .


    Der Code zur Abfrage ist folgender:

    Visual Basic-Quellcode

    1. Try
    2. conn.ConnectionString = myConnectionString
    3. conn.Open()
    4. da = New MySqlDataAdapter(dieser_sql, conn)
    5. Dim dt As New DataTable
    6. da.Fill(dt)
    7. 'Form1.Label2.Text = dt.Rows.Count.ToString
    8. 'Form1.DataGridView2.DataSource = dt
    9. '
    10. 'Form1.RichTextBox1.Text = Form1.DataGridView2.CurrentRow.Cells("Name").Value + vbNewLine + vbNewLine + Form1.DataGridView2.CurrentRow.Cells("Trainingsplan").Value
    11. SerialCode.DataGridView1.DataSource = dt
    12. SerialCode.Label2.Text = SerialCode.DataGridView1.CurrentRow.Cells("Serial").Value
    13. conn.Close()
    14. Catch ex As MySql.Data.MySqlClient.MySqlException
    15. MessageBox.Show(ex.Message)
    16. End Try


    Der Code für den sql Befehl ist dieser:

    Visual Basic-Quellcode

    1. sql = "SELECT * FROM Keys WHERE Key LIKE '" + TextBox1.Text + "'"
    2. abfrqage_ausfuehren_start_form_trainingsplan(sql)

    Leo&Eike schrieb:

    TEXT
    ist kein normaler String wie z.B. VarChar
    Es kann gut sein, dass da kein LIKE-Operator darauf angewendet werden kann.

    Was passiert bei

    SQL-Abfrage

    1. ​SELECT * FROM Keys WHERE Key LIKE '%1%'

    und was bei

    SQL-Abfrage

    1. SELECT * FROM Keys WHERE SUBSTR(Key,1,2000) LIKE '%1%'
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --

    MySqL pingelig wenn es um Schüsselwörter geht

    ich habs nur soweit getestet dass ich eine SELECT plus WHERE an einen MySQL Server gesendet hab, alles ok soweit.

    ABER
    mein SELECt ist ohne das SChlüsselwort 'Key'

    "Die Wörter in der folgenden Tabelle sind explizit für MySQL 5.1 reserviert. Für den Fall, dass Sie später einmal auf "
    Key ist dabei
    auf dieser Seite:
    dev.mysql.com/doc/refman/5.1/de/reserved-words.html
    JonDonym
    Eine Anonymisierung-Tool, das nicht nur deine IP verdeckt, sondern deine History, BrowserTyp, Windows-Version etc.
    Das Tool hat ca. 5 FreeKaskaden und ca. 10 Premium. Minimum 5 EUR für ein Volumen von 650MB.
    So habe Key jetzt zu Serial geändert auch in der DB, aber jetzt kommt folgende Fehlermeldung:

    Spoiler anzeigen
    Informationen über das Aufrufen von JIT-Debuggen
    anstelle dieses Dialogfelds finden Sie am Ende dieser Meldung.

    ************** Ausnahmetext **************
    System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    bei WindowsApplication1.SerialCode.abfrqage_ausfuehren_start_form_trainingsplan(String dieser_sql) in C:\Users\Niklas\Documents\Desktop\WindowsApplication1\WindowsApplication1\SerialCode.vb:Zeile 51.
    bei WindowsApplication1.SerialCode.Button1_Click(Object sender, EventArgs e) in C:\Users\Niklas\Documents\Desktop\WindowsApplication1\WindowsApplication1\SerialCode.vb:Zeile 76.
    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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    ************** Geladene Assemblys **************
    mscorlib
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.18444 built by: FX451RTMGDR.
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll.
    ----------------------------------------
    Leo & Eike - FirstStep
    Assembly-Version: 5.0.0.0.
    Win32-Version: 5.0.0.0.
    CodeBase: file:///C:/Users/Niklas/Documents/Desktop/WindowsApplication1/WindowsApplication1/bin/Release/Leo %26 Eike - FirstStep.exe.
    ----------------------------------------
    Microsoft.VisualBasic
    Assembly-Version: 10.0.0.0.
    Win32-Version: 11.0.50938.18408 built by: FX451RTMGREL.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll.
    ----------------------------------------
    System
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.18408 built by: FX451RTMGREL.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll.
    ----------------------------------------
    System.Core
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.18408 built by: FX451RTMGREL.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll.
    ----------------------------------------
    System.Windows.Forms
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.18408 built by: FX451RTMGREL.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll.
    ----------------------------------------
    System.Drawing
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.18408 built by: FX451RTMGREL.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll.
    ----------------------------------------
    System.Configuration
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.18408 built by: FX451RTMGREL.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll.
    ----------------------------------------
    System.Xml
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.34234 built by: FX452RTMGDR.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll.
    ----------------------------------------
    System.Runtime.Remoting
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.34108 built by: FX45W81RTMGDR.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll.
    ----------------------------------------
    MySql.Data
    Assembly-Version: 1.0.10.0.
    Win32-Version: 1.0.10.0.
    CodeBase: file:///C:/Users/Niklas/Documents/Desktop/WindowsApplication1/WindowsApplication1/bin/Release/MySql.Data.DLL.
    ----------------------------------------
    System.Data
    Assembly-Version: 4.0.0.0.
    Win32-Version: 4.0.30319.18408 built by: FX451RTMGREL.
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll.
    ----------------------------------------
    System.Windows.Forms.resources

    ...