我有一個程序,用戶可以通過在文本框中輸入舊密碼並在獨立的文本框中輸入新密碼來更新其密碼。cmd.executeNonQuery()更新
更新查詢然後用新密碼更新數據庫。
Try
If tbOldPassword.Text <> "" Then
For Each Row In ds.Tables("sqlAddNewDetails").Rows
If Row.Item(0) = gblstrUserID Then
If Row.Item(1) = tbOldPassword.Text Then
If tbPassword.Text = tbRePassword.Text Then
'Updates the database
sqlUpdate = ("UPDATE Users SET Password = '" & tbPassword.Text & "' WHERE userID = " & Row.Item(0))
Dim cmd As New OleDbCommand(sqlUpdate, con)
cmd.ExecuteNonQuery()
MsgBox("Password successfully changed")
Else : MsgBox("The passwords are not the same")
End If
Else : MsgBox("Invalid old password")
End If
End If
Next
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
然而,每次的代碼獲取到cmd.ExecuteNonQuery(),它拋出了一個錯誤,指出存在的更新查詢語法錯誤。但是,如果我在Microsoft Access中使用此查詢,它工作正常,以便更新查詢本身寫入正確。什麼可能是錯的?
注意:我在同一Sub例程內的另一段代碼中使用UPDATE查詢,它在那裏工作。它關於這個查詢的東西。
注意那句話:如果我改變更新查詢來更新用戶設置電子郵件= ' 「& tbPassword.Text &」' 其中userid = 「& Row.Item(0)」 它的工作原理。關於引發錯誤的密碼。
你有什麼錯誤信息? – 2012-04-15 14:16:42
UPDATE語句中的語法錯誤。 – 2012-04-15 14:19:08