在下面的代码片段中,我尝试使用mysql语句通过 vb.net
中的应用程序界面更新 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
我收到以下错误: 您的SQL语法中有错误;请查看与您的MySql服务器版本对应的手册,以便在'(.......'第1行)附近使用正确的语法
以下是包含错误的图片:
答案 0 :(得分:1)
您不需要在UPDATE
statemtment中使用括号,可以用逗号设置多个字段,例如:
Query = "UPDATE student.student_info set Student_Name='" & SName.Text & "', Date_of_Birth='" & DateTimePicker1.Text & "',Department='" & ComboBoxDept.Text & "' where Roll_Number = '" & SRoll.Text & "';"