【发布时间】:2014-07-23 16:42:00
【问题描述】:
我使用此查询,但没有得到正确的结果
我的桌子:http://i.stack.imgur.com/CuBOM.png
我的应用:http://i.stack.imgur.com/1EaQs.png
用户将选择2个日期,结果是2个日期之间所有天的班次总和
这是我的代码:
cn.Open()
cmd.CommandType = CommandType.Text
cmd.CommandText = " SELECT SUM(shift1) + SUM(shift2) + SUM(shift3) as shifts
FROM Statistique
where nom_produit = '" & ComboBox4.Text & "'
and P_Date BETWEEN #" & DateTimePicker2.Text & "#
AND #" & DateTimePicker3.Text & "#
group by nom_produit "
cmd.Connection = cn
Dim st As Integer = cmd.ExecuteScalar
cn.Close()
Label36.Text = st
Label35.Text = st + st / 100 * 20
并且此查询在 MS Access 2007 中正常工作:
SELECT SUM(shift1) + SUM(shift2) + SUM(shift3) AS shifts
FROM Statistique
WHERE nom_produit = 'BAGS 1000x700'
AND p_date BETWEEN #10/07/2014# AND #16/07/2014#
GROUP BY nom_produit
现在我想让它在我的 VB.net 项目中工作。
编辑:当我使用单引号而不是 # 时出现此错误:oledbexception 未处理:Type de données incompatible dans l'expression du critère。
【问题讨论】:
-
您是否有任何与 MySQL 的数据库连接?我认为,这是一个 MS Access 唯一的问题。
-
我在 vb.net 中使用 MS Access 数据库
-
好的,但是你声明
and this query work properly in MS Access 2007。而您使用的是VB.NET,那么您的实际问题是什么?然后不要使用'引号。 -
如果您使用日期选择器删除 2 个条件,它是否有效?用于测试..