我有一张表,我需要更新用户密码,其中用户名存储在会话中。但是,我收到此错误:“操作必须使用可更新的查询”,即使我已授予所有用户和管理员完全控制权。
以下是我的代码:
string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\inetpub\wwwroot\myfolder\mydatabase";
using (OleDbConnection con = new OleDbConnection(str))
using (OleDbCommand cmd = con.CreateCommand())
{
cmd.CommandText = "UPDATE [users] SET [password] = ? WHERE username = ?";
cmd.Parameters.Add("password", OleDbType.VarChar).Value = Request.Form["conPassword"];
cmd.Parameters.Add("username", OleDbType.VarChar).Value = (string)Session["username"];
con.Open();
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Your password has been changed successfully.");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}