請幫助,我有一個問題,用asp.net網頁語法更新位數據類型。這裏是我的代碼無法更新位數據類型sql服務器的網頁
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 [email protected]";
db.Execute(updateCommand1, idAdmin2);
var updateCommand2 = "UPDATE UserProfile SET onDuty= 1 WHERE [email protected]";
db.Execute(updateCommand2, idAdmin);
Response.Redirect("~/SuperAdmin/diklat");
}
模塊想做到這一點:編輯聯繫的bit數據類型的狀態(值班與否)。我遇到的情況是一旦管理員更新爲新的,舊數據類型的onDuty不會更新爲0(從1開始),但新的成功更新爲1(從0開始)。對不起,長代碼,問題很簡單,但我只是想確保這個問題不是來自我的代碼中的任何其他地方。希望它足夠清楚
注意:根本沒有錯誤公告!該頁仍然有效,只有數據庫中的數據未更新
-1發佈這麼多的代碼。你不能縮小你的問題,只發布相關的代碼? –
好吧,我已經編輯它,希望它縮小它PAL @JohnSaunders –