简体   繁体   English

mysql中的tinyint在c#中显示为布尔值

[英]tinyint in mysql is shown as boolean value in c#

My query to get a tinyint(1) field from a table in mysql in as below 我的查询从mysql的表中获取tinyint(1)字段如下

mysqlcommand.selectquery="select vehicletype from vehicles where id=1"

possible values for vehicletype is 1 to 7 vehicletype类型的可能值为1到7

but the output in the datatable row for the field is shown as boolean 但在输出datatable行的字段被示出为boolean

datatable dtresult;
mda.Fill(dtResult);
DataRow dr = dtResult.Rows[0];
//dr["vehicletype "]=false if 0
//dr["vehicletype "]=true if 1
//dr["vehicletype "]=true if 2
//dr["vehicletype "]=true if 3
//dr["vehicletype "]=true if 4 etc...

when i see the value of dr["vehicletype "] in visual studio it shows as false for 0 and true for any other value. 当我看到的值dr["vehicletype "]在Visual Studio中它显示为false 0和true为任何其他值。 How can i prevent it from default conversion 我如何防止它进行默认转换

Refer to: 参考:

https://bugs.mysql.com/bug.php?id=67381 https://bugs.mysql.com/bug.php?id=67381

You can add to your connection string "Treat Tiny As Boolean=false;" 您可以在连接字符串中添加“ Treat Tiny As Boolean = false;”。

and now the tinyint will be interpreted like a type sbyte in C#. 现在,tinyint将被解释为C#中的sbyte类型。

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

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