【问题标题】:Error in SQL syntax Can seem to find the right querySQL 语法错误 似乎可以找到正确的查询
【发布时间】:2015-06-11 18:08:18
【问题描述】:

我遇到了问题,我似乎无法正确地进行 sql 查询

                Dim command1 As New MySqlCommand("UPDATE userscanner SET Username ='" & txtbox_username.Text & "',Password='" & txtbox_password.Text & "' WHERE ID = '" & lbl_id.Text & "')", Connection)
                command1.ExecuteNonQuery()
                MsgBox("Profile Successfuly Saved")
                Me.Close()

但我有一个错误提示“您的 sql 语法有错误;请查看与您的 MySQL 服务器版本对应的手册,以在第 1 行的 ')' 附近使用正确的语法

顺便说一句,我使用 XAMPP 和 MYSQL 作为数据库

【问题讨论】:

  • & "')" 中删除)
  • 欢迎来到 stackoverflow.com! :-) 语句中的大括号数量不平衡。语句末尾有一个额外的大括号。这就是错误消息试图告诉您的内容。
  • 你真的应该使用参数化查询来避免sql注入。而且,正如其他人所说,您不需要在& "')" 之后的) lbl_id.Text

标签: php mysql sql-server vb.net


【解决方案1】:

你有多余的')'

更正:

            Dim command1 As New MySqlCommand("UPDATE userscanner SET Username ='" & txtbox_username.Text & "',Password='" & txtbox_password.Text & "' WHERE ID = '" & lbl_id.Text & "'", Connection)
            command1.ExecuteNonQuery()
            MsgBox("Profile Successfuly Saved")
            Me.Close()

【讨论】:

    【解决方案2】:

    试试这个:

            Dim command1 As New MySqlCommand("UPDATE userscanner SET Username ='" & txtbox_username.Text & "',Password='" & txtbox_password.Text & "' WHERE ID = '" & lbl_id.Text & "'", Connection)
            command1.ExecuteNonQuery()
            MsgBox("Profile Successfuly Saved")
            Me.Close()
    

    【讨论】:

      【解决方案3】:

      在构造 sql 语句时,您似乎包含了一个没有左括号的 ')' 右括号

      【讨论】:

        【解决方案4】:

        我认为您需要删除 ')'。

        Dim command1 As New MySqlCommand("UPDATE userscanner SET Username ='" & txtbox_username.Text & "',Password='" & txtbox_password.Text & "' WHERE ID = '" & lbl_id.Text & "'", Connection)
        

        【讨论】:

          【解决方案5】:

          您应该使用参数化更新查询

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2013-12-15
            • 2012-06-18
            • 1970-01-01
            • 2023-01-08
            • 2012-02-15
            • 1970-01-01
            • 2017-07-26
            相关资源
            最近更新 更多