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 8039649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:38:22+00:00 2026-06-05T03:38:22+00:00

So in C# whenever I retrieved a tinyint from my MSSQL database I used

  • 0

So in C# whenever I retrieved a tinyint from my MSSQL database I used the following cast.

(int)(byte)reader["MyField"];

However, that cast doesn’t seem to work in MySQL.

What I have tried

(byte)reader["MyField"];

and just

(int)reader["MyField"];

Edit 1

Exception

The specified cast is not valid.

Edit 2

This is the data type.

{Name = "SByte" FullName = "System.SByte"}
  • 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-05T03:38:23+00:00Added an answer on June 5, 2026 at 3:38 am

    The problem is that due to casting and explicit operators:

    (byte)objectExpression is is not the same as (byte)sbyteExpression.

    The first is a [direct] cast which fails because the real object type is sbyte and not byte. The latter will perform a conversion that just happens to use a explicit operator (an “Explicit Conversion”) with syntax that, unfortunately, still looks like a [direct] cast as per above. Here is an example of it failing sans-database:

    var obj = (object)(sbyte)0;
    var i1 = (int)(sbyte)obj;  // okay: object (cast)-> sbyte (conversion)-> int
    var i2 = (int)obj;         // fail: sbyte (cast)-> int (but sbyte is not int!)
    

    Either use an (sbyte)objectExpression cast which is valid for the real object type, or Convert.ToInt32(objectExpression) which takes an object and does some magic to convert it to an int. (Using Convert.ToByte could throw an exception on overflow.)

    Happy coding!

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

Sidebar

Related Questions

Whenever I deploy a production application that has an error with an externalized configuration
Imagine you have a website with several drop-downs that are populated from the back-end
I'm trying to retrieve note titles from a specific notebook whenever the user clicks
I have a problem that whenever I'm inserting data using coredata, everything's going fine.
While echoing a form from PHP with some predefined value retrieved from file from
I am trying to Sync a bunch of Videos I've retrieved from a particular
Well, I'm designing an online service that needs subscription in order to be used
I am parsing data from a website via xml that always changes so I
I want to copy int[] named idNumbers from session scope to request scope. The
I want to add some methods to the context retrieved from a canvas object.

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.