简体   繁体   English

将MySql Tinyint(1)数据类型检索到.Net应用程序中

[英]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. 我正在使用MySQL Connector / Net v.6.6.5从远程MySql数据库将数据提取到.Net应用程序中。 One of the columns being read from the MySql database is a tinyint(1) data type containing values from 0-5. 从MySql数据库读取的列之一是tinyint(1)数据类型,其中包含0-5的值。 The problem is that the connector reads this column type as a bool (true/false) instead of an int. 问题在于连接器将这种列类型读取为布尔值(true / false)而不是int。 Thus, everything greater than 0 is returned as a one. 因此,大于0的所有内容都将返回为1。 This is a big problem. 这是个大问题。 I don't have the luxury of altering the database column. 我没有改变数据库列的奢侈。

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. 使用MySql.data.dll驱动程序返回TRUE或FALSE,可以轻松将其转换为1或0。但是,从tinyint(1)列读取的数据包含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. 这从MySql tinyint列中得出了正确的值(0-5)。 Hopefully it will help someone in the same situation in the future. 希望它会在将来对同样情况的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM