MySQL 中的 tinyint 在 C# 中显示为布尔值

本文关键字:显示 布尔值 中的 tinyint MySQL | 更新日期: 2023-09-27 18:37:09

我的查询从 mysql 中的表中获取tinyint(1)字段,如下所示

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

vehicletype 的可能值为 1 到 7

但该字段的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...

当我在Visual Studio中看到dr["vehicletype "]的值时,它显示为0的false,任何其他值显示为true。如何防止它的默认转换

MySQL 中的 tinyint 在 C# 中显示为布尔值

参考:

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

可以添加到连接字符串 "将微小视为布尔值=假;"

现在 tinyint 将被解释为 C# 中的类型字节。