【发布时间】:2020-03-03 07:01:13
【问题描述】:
如何将从数据库读取的位数据库值设置为布尔会话变量,该变量将从第 1 页传递到第 2 页。在第 2 页上,我需要在读取其值之前验证该变量不为空. “管理员”列是位类型。
page1.aspx:
bool IsAdmin = (bool)reader["Administrator"]; // getting Specified cast is not valid here if null
if (IsAdmin)
{
Session["IsAdministrator"] = true;
}
else
{
Session["IsAdministrator"] = false;
}
page2.aspx:
//This is how I would check that the variable is not null if it were a string, how do I check the same for a Boolean?
Boolean isAdmin;
if (!string.IsNullOrEmpty(Session["IsAdministrator"] as string))
{
isAdmin = (bool)(Session["IsAdministrator"]);
}
【问题讨论】:
-
你能澄清你的问题吗?