這是我的示例代碼mysql vb.net中更新查詢的正確語法是什麼?
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服務器版本使用附近的正確語法手冊的突破,挑戰昨天的舊格局,創造未來的N'位於第1行
這是來自不使用參數。參數化你的SQL查詢,它會按你的預期工作。請閱讀更多信息:http://jmcilhinney.blogspot.com.au/2009/08/using-parameters-in-adonet.html – jmcilhinney