MySQL查询后VB.Net数据表将整数值视为小数
在 VB (Winforms) 中,我从 MySQL 数据库中提取统计信息,生成的数据表用于构建不同的图表。给我的印象是,根据 MySQL 查询,在某些情况下,纯整数值在数据表中被视为小数,因此我的图表看起来很奇怪,其网格线用分数 1 表示。示例如下。
当我在查询中使用灌浆时,结果不是我所期望的。查询如下所示:
select Cell,Time,
sum(counter12) as counter
from h_cell
where cell='ABC' and time>='2018-05-26' and time<='2018-06-01'
group by Cell,Time
在本例中,数据表列“counter”的数据类型是“System.Decimal”。我需要强调的是,该值始终是整数。我也无法避免在我的查询中陷入困境。问题是我的图表看起来不正确,网格线显示的值小于一。
当我设计查询而不进行分组时,数据表中列的数据类型是“System.Int32”,然后图表看起来应该是这样。
select Cell,Time,
(counter12) as counter
from h_cell
where cell='ABC' and time>='2018-05-26' and time<='2018-06-01'
有没有办法避免这种不一致?
In VB (Winforms) I am extracting statistics from MySQL database and the resulting datatable is used to build different charts. What made me impression is that depending on MySQL query in some cases pure integer values are considered as decimals in datatable and thus my charts look strange with their grid lines depicted with fractions of 1. Examples are below.
When I use in my query grouing the result is not what I expect. Query looks like following:
select Cell,Time,
sum(counter12) as counter
from h_cell
where cell='ABC' and time>='2018-05-26' and time<='2018-06-01'
group by Cell,Time
In this case the datatype of datatable's column 'counter' is 'System.Decimal'. I need to stress that the value is always integer. Also I cannot avoid grouing in my query. The problem is that my chart looks not right with grid lines showing values less than one.
When I design my query without grouping then datatype of the column in datatable is 'System.Int32' and then chart looks as it should.
select Cell,Time,
(counter12) as counter
from h_cell
where cell='ABC' and time>='2018-05-26' and time<='2018-06-01'
Is there a way to avoid this inconsistency?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想查看 MySQL 中的表结构,并参考此页面的等效内容来了解为什么您可能会获得 Decimal 类型: Visual Basic / MySQL 数据类型
您可能会尝试的其他方法(正如其他人建议的那样)是将其转换为您的数据类型正在期待。唯一的区别是我不会投射你的专栏,但你的总和结果如下:
You might want to take a look at the table structure in MySQL and refer to this page for the equivalent to see why you might be getting a Decimal type: Visual Basic / MySQL Datatypes
Something else you might try (as someone else suggested) is to cast to the data type you are expecting. The only difference is that I would not cast your column, but the result of your sum as follows: