【发布时间】:2020-06-15 23:42:37
【问题描述】:
我的表单加载事件有查询,将显示总销售额,
lbldate.Text = DateTime.Now.ToString("dd/M/yyyy");
try
{
MyConN.Open();
OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = MyConN;
Cmd.CommandText = "Select Sum(TotalSales) from LSales where DISTINCT SDate='" + "label7.Text" + "'";
//OleDbDataReader ReadeR = Cmd.ExecuteReader();
}
catch(Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
but this code throwing
>"syntax error (missing operator) in query expression `'DISTINCT SDate='16/6/2020''`
i want to sum all `totalsales` base on date
【问题讨论】:
-
您应该从查询中删除 DISTINCT。
-
@chetan,删除 DISTINCT 错误仍然存在,数据类型不匹配
-
你试过sql server中的查询吗?
-
@sajid,因为我没有尝试使用 access 作为数据库
-
对我来说,你有两个问题,第一个提到了@ChetanRanpariya,第二个是
label7.Text周围的双引号,这应该可以:SELECT SUM(TotalSales) as Total FROM LSales WHERE SDate='" + label7.Text + "'"