MySQL查询后VB.Net数据表将整数值视为小数

发布于 2025-01-12 00:38:18 字数 954 浏览 1 评论 0原文

在 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.

enter image description here

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'

enter image description here

Is there a way to avoid this inconsistency?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后eg是否自 2025-01-19 00:38:18

您可能想查看 MySQL 中的表结构,并参考此页面的等效内容来了解​​为什么您可能会获得 Decimal 类型: Visual Basic / MySQL 数据类型

您可能会尝试的其他方法(正如其他人建议的那样)是将其转换为您的数据类型正在期待。唯一的区别是我不会投射你的专栏,但你的总和结果如下:

select Cell,Time,
Cast(sum(counter12) As SIGNED) as counter
from h_cell
where cell='ABC' and time>='2018-05-26' and time<='2018-06-01'
group by Cell,Time

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:

select Cell,Time,
Cast(sum(counter12) As SIGNED) as counter
from h_cell
where cell='ABC' and time>='2018-05-26' and time<='2018-06-01'
group by Cell,Time
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文