gpt4 book ai didi

c# - mysql中的tinyint在c#中显示为 bool 值

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:36 26 4
gpt4 key购买 nike

我的查询从 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值(value)。我怎样才能防止它默认转换

最佳答案

引用:

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

You can add to your connection string "Treat Tiny As Boolean=false;"

and now the tinyint will be interpreted like a type sbyte in C#.

关于c# - mysql中的tinyint在c#中显示为 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19650340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com