Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving a MySql Tinyint(1) data type into a .Net application

I am using MySQL Connector/Net v.6.6.5 to pull data into my .Net application from a remote MySql database. One of the columns being read from the MySql database is a tinyint(1) data type containing values from 0-5. The problem is that the connector reads this column type as a bool (true/false) instead of an int. Thus, everything greater than 0 is returned as a one. This is a big problem. I don't have the luxury of altering the database column.

like image 509
mrtedweb Avatar asked Jan 18 '26 21:01

mrtedweb


1 Answers

Below is the solution I ended up using. My original query was:

SELECT tinyint_column FROM table_with_a_tinyint

Using MySql.data.dll driver returns either TRUE or FALSE, which can easily be converted to a 1 or 0. But the data being read from the tinyint(1) column contained 0-5. I was able to extract the correct values by editing my query to below:

SELECT (tinyint_column+0) FROM table_with_a_tinyint

This yielded the correct values (0-5) from the MySql tinyint column. Hopefully it will help someone in the same situation in the future.

like image 140
mrtedweb Avatar answered Jan 20 '26 12:01

mrtedweb