简体   繁体   English

通过 vb.net 在 mysql 中更新数据库时出现语法错误

[英]syntax error while updating database in mysql through vb.net

In the following code snippet I have tried to update the student_info table using mysql statements through an application interface in vb.net在以下代码片段中,我尝试通过vb.net 中的应用程序界面使用 mysql 语句更新student_info

Dim Connection As MySqlConnection
    Dim Command As MySqlCommand
    Connection = New MySqlConnection
    Connection.ConnectionString =
        "server=localhost;userid=root;password=root;database=student;"

    Try
        Dim DataReader As MySqlDataReader
        Connection.Open()
        Dim Query As String
        Query = "UPDATE student.student_info set (Student_Name='" & SName.Text & "',Date_of_Birth='" & DateTimePicker1.Text & "',Department='" & ComboBoxDept.Text & "') where Roll_Number = '" & SRoll.Text & "';"
        Command = New MySqlCommand(Query, Connection)
        DataReader = Command.ExecuteReader()
        MessageBox.Show("Data is Updated !")
        DataReader.Close()
        Connection.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        Connection.Dispose()
    End Try

I received the following error : You have an error in your SQL syntax;check the manual the corresponds to your MySql server version for the right syntax to use near '(.......' at line 1我收到以下错误:您的 SQL 语法有错误;请检查与您的 MySql 服务器版本相对应的手册,以了解在第 1 行的“(.......”附近使用的正确语法

Here is the included image for error :这是包含的错误图像:

Error Image错误图像

UPDATE语句中不需要使用括号,可以用逗号设置多个字段,例如:

Query = "UPDATE student.student_info set Student_Name='" & SName.Text & "', Date_of_Birth='" & DateTimePicker1.Text & "',Department='" & ComboBoxDept.Text & "' where Roll_Number = '" & SRoll.Text & "';"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM