Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:10:15+00:00 2026-06-14T10:10:15+00:00

My Users table has a field called Admin which is tinyint(1) . 1 for

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:10:16+00:00Added an answer on June 14, 2026 at 10:10 am

    That’s because tinyint gets turned into a System.Byte which can’t be explicitly cast to an System.Int32

    You will have to use Convert.ToInt32(Byte)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a series of codes, which has a field called
I have a user table 'users' that has fields like: id first_name last_name ...
I have a table User which has the fields (id, first_name, middle_name, last_name). I
I have a table users which has a primary key userid and a datetime
I have an application which has a Projects table and a Users table. In
I have a table users with primary index userId . Currently, each user has
I'm working with a table that has a field called other_group_ids that is of
I have a base table called users which holds all common information about a
I want to search for column/field called ACC I have 28 users. I got
I have a table called users in a PostgreSQL database. It has name ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.