我在數據庫中插入新記錄時出錯。任何幫助請 錯誤是「INSERT INTO語句中的語法錯誤。」 好吧,我添加完整的語法。INSERT INTO語句中的語法錯誤vb2008
Dim dbCommand As OleDbCommand
Dim DBConn As OleDbConnection
Dim DBInsert As New OleDbCommand()
myword = "عابد"
mypronounce = "عابِد [عا + بِد]"
mylanguage = "(عربی)"
mysiga = "( مذکر - واحد )"
mymuradifat = "زاہِد, پُجاری, مُتَّقی, پارْسا, نیک, صالِح, تَپَسّی, ذاکِر, سَنْت, صُوفی, خُدا پَرَسْت"
myenglish = "An adorer, worshipper, votary, devotee "
mymurakbat = "لَکھْنَوی دَبِسْتان, لَکھْنَوی سِکُول"
myword = Replace(myword, "'", "''")
mypronounce = Replace(mypronounce, "'", "''")
mylanguage = Replace(mylanguage, "'", "''")
mysiga = Replace(mysiga, "'", "''")
mymuradifat = Replace(mymuradifat, "'", "''")
myenglish = Replace(myenglish, "'", "''")
mymurakbat = Replace(mymurakbat, "'", "''")
' & "(word,pronounce,language,siga,mutradifat,english,murakabat) " _
DBConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=xxxxxxxx;")
DBInsert.CommandText = "Insert Into data " _
& "(word,pronounce,language,siga,mufradat,english,murakabat) " _
& "Values (" _
& "'" & myword & "', " _
& "'" & mypronounce & "', " _
& "'" & mylanguage & "', " _
& "'" & mysiga & "', " _
& "'" & mymuradifat & "', " _
& "'" & myenglish & "', " _
& "'" & mymurakbat & "')"
DBInsert.Connection = DBConn
DBInsert.Connection.Open()
DBInsert.ExecuteNonQuery()
DBConn.Close()
是的,這是真的舊學校的代碼,並受到SQL注入攻擊 – 2012-03-20 14:37:04
需要看到錯誤信息。 – javram 2012-03-20 14:37:48
說真的 - 你應該**總是**使用參數化查詢 - 現在每個人都應該知道,我會想! [看看這個偉大的漫畫](http://xkcd.com/327/)和[閱讀更多關於參數化查詢](http://www.codinghorror.com/blog/2005/04/give-me-parameterized -sql-or-give-me-death.html) – 2012-03-20 14:40:29