2014-09-27 125 views
0

我在VB.NET中編碼,當我試圖插入記錄時遇到此錯誤我的SQL數據庫。你的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,在第1行'')附近使用正確的語法

Public Sub SaveNames(ByRef SQLStatement As String) 
    Dim cmd As MySqlCommand = New MySqlCommand 

    With cmd 
     .CommandText = SQLStatement 
     .CommandType = CommandType.Text 
     .Connection = SQLConnection 
     .ExecuteNonQuery() 
    End With 
    SQLConnection.Close() 
    MsgBox("Successfully Added") 
    SQLConnection.Dispose() 


End Sub 

Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click 
    Dim SQLStatement As String = "INSERT INTO people(name) VALUES (‘" & TextBox1.Text & "')" 

    SaveNames(SQLStatement) 

End Sub 
+0

這是一種智能報價?你使用MSWord進行編碼嗎? – Strawberry 2014-09-27 17:10:30

+1

** [如何創建參數化SQL查詢?我爲什麼要?](http://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i)** – 2014-09-27 17:13:38

回答

0

看起來你已經得到了微軟的那些時髦的報價的,而不是單引號字符

VALUES (‘" & 
     ^

替換,與正常的單引號,試一試,看看有多大的煙那麼球呢。

相關問題