How do I retrieve a data type of tinyint from MySQL in C#?

meanbunny picture meanbunny · Jun 7, 2012 · Viewed 10.4k times · Source

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"}

Answer

usr picture usr · Jun 7, 2012

To determine the proper type, look at the value of

reader["MyField"].GetType()

in the debugger.