"System.Data.OleDb.OleDbException: '構文のエラーがUPDATEステートメントでエラー"

2017-06-07 18 views
0

良い日、私は "System.Data.OleDb.OleDbException:'構文エラーのUPDATEステートメント"エラーが表示され続けます。"System.Data.OleDb.OleDbException: '構文のエラーがUPDATEステートメントでエラー"

誰かがなぜ、どこで助けてくれますか?私はしかし、SQLパラメータを使用することをお勧めし

Dim cmd As New OleDbCommand("UPDATE tblCreate Set Username = '" & txtUserName.Text & "', EMail = '" & txtEmail.Text & "', FirstName = '" & TxtName.Text & "', LastName = '" & txtSurname.Text & "', Access = '" & cmbAccess.SelectedItem & "', CreatedBY = '" & Label9.Text & "', DateCreated = '" & Label10.Text & "', ChangedBY = '" & Label6.Text & "', DateChanged = '" & Date.Now.ToString("yyyy-MMMM-dd hh:mm tt") & "' WHERE UserName = '" & txtUserName.Text & "';") 


は、すべてのヘルプは大以下

があなたのwhere句、試すにアポストロフィを逃しているようなコード

Try 
     conec.Open() 

     Dim cmd As New OleDbCommand("UPDATE tblCreate Set Username = '" & txtUserName.Text & "', EMail = '" & txtEmail.Text & "', FirstName = '" & TxtName.Text & "', LastName = '" & txtSurname.Text & "', Access = '" & cmbAccess.SelectedItem & "', CreatedBY = '" & Label9.Text & "', DateCreated = '" & Label10.Text & "', ChangedBY = '" & Label6.Text & "', DateChanged = '" & Date.Now.ToString("yyyy-MMMM-dd hh:mm tt") & "' WHERE UserName = " & txtUserName.Text & ";") 


     cmd.CommandType = CommandType.Text 
     cmd.Connection = conec 
     cmd.ExecuteNonQuery() 
     MessageBox.Show("Data Updated" & vbCrLf & "Done") 
     conec.Close() 

    Catch ex As Exception 
     MessageBox.Show(ex.Message) 
    End Try 
+1

常にSQLパラメータを使用してください。それは単にSQLを構成するのが面倒なことではありません。また、[ask]を読んで[tour] – Plutonix

答えて

1

が見えるあるにappriciatedされます彼らは維持するのがずっと簡単です。

関連する問題