My Users table has a field called Admin
which is tinyint(1)
. 1 for admin, 0 for normal user.
I want to set a session variable when users log in that is either true or false depending on if they're admin or not.
if ((int)Reader["Admin"] == 0)
{
HttpContext.Current.Session["Admin"] = false;
}
else
{
HttpContext.Current.Session["Admin"] = true;
}
Reader
is a SqlDataReader
. The code produces the following error:
System.InvalidCastException: Specified cast is not valid.
How can I properly cast Reader["Admin"]
to an int?