[英]i get error when i try to run query in access through C#
i have this query: 我有这个查询:
SELECT DO3Tbl.CodeDip, DO3Tbl.BarcodeD, Sum(DO3Tbl.Qty) AS Qty,
Max(DO3Tbl.Mly) AS Mly, [Qty]-[Mly] AS Tot, ABS(Tot) AS TotAbs
when i run this query in access its work's excellent 当我在访问中运行此查询时,它的工作非常出色
but when i run this query in C# code like this: 但是当我使用C#代码运行此查询时,如下所示:
SQL = SELECT DO3Tbl.CodeDip, DO3Tbl.BarcodeD, Sum(DO3Tbl.Qty) AS Qty,
Max(DO3Tbl.Mly) AS Mly, [Qty]-[Mly] AS Tot, ABS(Tot) AS TotAbs
Cmd = new OleDbCommand(SQL, Conn);
Cmd.ExecuteNonQuery();
Cmd.Dispose();
i get this error: 我收到此错误:
You tried to execute a query that does not include the specified expression '[Qty]-[Mly]' as part of an aggregate function.
您试图执行不包含指定表达式'[Qty]-[Mly]'作为聚合函数一部分的查询。
There is quite a lot wrong with the query as far as Access is concerned, for example, you are not selecting from any table, also, you cannot use an Alias that is the sames as a field name. 就Access而言,查询存在很多错误,例如,您没有从任何表中进行选择,而且,您不能使用与字段名称相同的别名。 How about:
怎么样:
SELECT DO3Tbl.CodeDip, DO3Tbl.BarcodeD, Sum(DO3Tbl.Qty) AS SumOfQty, Max(DO3Tbl.Mly) AS MaxOfMly, Sum([Qty]-[Mly]) AS Tot, Abs(Tot) AS TotAbs
FROM DO3Tbl
GROUP BY DO3Tbl.CodeDip, DO3Tbl.BarcodeD;
I propose that instead of counting the 我建议不要计算
Tot and TotAbs
Tot和TotAb
values directly in the query. 值直接在查询中。
It's better to count them in the code since we are able to avoid any issue related to the query execution order in the SELECT clause. 最好将它们计入代码中,因为我们能够避免任何与SELECT子句中的查询执行顺序有关的问题。
Hence your query would be like that: 因此,您的查询将是这样的:
SELECT DO3Tbl.CodeDip, DO3Tbl.BarcodeD, Sum(DO3Tbl.Qty) AS Qty,
Max(DO3Tbl.Mly) AS Mly
Cheers. 干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.