mysql vb.net中更新查询的正确语法是什么?

时间:2017-10-11 03:19:16

标签: mysql vb.net visual-studio-2017

这是我的示例代码

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        myConn = New MySqlConnection
    myConn.ConnectionString = "server=localhost;userid=root;password=root;database=itss"
    Dim reader As MySqlDataReader

    Try
        myConn.Open()
        Dim query As String
        query = "update itss.announcement set annoMessage = '" & TextBox1.Text & "' where idAnno = 3"
        command = New MySqlCommand(query, myConn)
        reader = command.ExecuteReader
        myConn.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        myConn.Dispose()
    End Try
    'strMessage = TextBox1.Text
    Form1.GroupBox1.Select()
    Form1.Activate()
    Form4.Activate()
    Me.Hide()
End Sub

当我点击按钮时,会出现一个异常

你的sql语法有错误;检查与你的mysql服务器版本相对应的手册,以获得正确的语法,使用附近的突破来挑战昨天的旧模式,并在第1行创建明天的n'

1 个答案:

答案 0 :(得分:1)

问题是您在b语句中使用带有连接参数字符串的std::min(static_cast<float>(a), b)。您应该使用reader = command.ExecuteReader参数化查询,如下所示:

UPDATE

注意:ExecuteNonQuery用于返回myConn.Open() Dim query As String query = "update itss.announcement set annoMessage = @message where idAnno = 3" command = New MySqlCommand(query, myConn) command.Parameters.Add("@message", MySqlDbType.VarChar).Value = TextBox1.Text reader = command.ExecuteNonQuery() ' this is used for UPDATE statement myConn.Close() 语句的查询结果,即ExecuteReader