请帮忙,我在使用 asp.net 网页语法更新位数据类型时遇到问题。这是我的代码
var db = Database.Open("StarterSite");
var idAdmin = ""; // Here's the ID of the new Admin
var idAdmin2 = ""; // Here's The ID of the old Admin
if(!IsPost){
if(!Request.QueryString["id"].IsEmpty() && Request.QueryString["id"].IsInt()) {
diklatid = Request.QueryString["id"];
var dbCommand = "SELECT * FROM diklat WHERE ID_diklat = @0";
var row = db.QuerySingle(dbCommand, diklatid);
if(row != null) {
string rowidadmin = row.ID_Admin.ToString();
idAdmin2 = rowidadmin; // Inserted the ID value of old admin to this variable
}
else{
Validation.AddFormError("No data choosen");
}
}
else{
Validation.AddFormError("No data choosen");
}
}
if(IsPost){
idAdmin = Request.Form["idAdmin"]; //The ID value of new admin comes from the Form
if (idAdmin == idAdmin2){
//Check if the new admin equals to old admin
-------------------//do something------
Response.Redirect("~/SuperAdmin/diklat");
}
else
{
//-----------------------------The Main Problem------------------------
// If different it suppose to change "onDuty" variable of the new one to 1 (true) and the old one to 0 (false)
var updateCommand1 = "UPDATE UserProfile SET onDuty= 0 WHERE UserId=@0";
db.Execute(updateCommand1, idAdmin2);
var updateCommand2 = "UPDATE UserProfile SET onDuty= 1 WHERE UserId=@0";
db.Execute(updateCommand2, idAdmin);
Response.Redirect("~/SuperAdmin/diklat");
}
模块假设这样做:以位数据类型编辑管理员的状态(值班与否)。我遇到的情况是一旦管理员更新到新的,作为旧的位数据类型的 onDuty 不会更新为 0(从 1),但新的成功更新为 1(从 0)。抱歉,代码很长,问题很简单,但我只是想确保这个问题不是来自我的代码中的其他任何地方。希望它足够清楚
注意:根本没有错误公告!页面仍然有效,只是数据库中的数据没有更新