0

我想使用此查询填充 dataGridView1,此查询返回正确的结果,但它在 c#.net 代码中引发错误。

        string sql = "SELECT bill_no, name_shop, SUM(qty * price) as [Total],dt FROM purchase_stock_entry INNER JOIN purchase_party_name ON purchase_stock_entry.purchase_party_id = purchase_party_name.id GROUP BY bill_no, name_shop;";
        DataSet ds = new DataSet();
        OleDbCommand cmd = new OleDbCommand(sql, con);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        da.Fill(ds);
        dataGridView1.DataSource = ds.Tables[0];


        **Error : You tried to execute a query that does not include the 
        specified expression 'total' as part of an aggregate function.**
4

1 回答 1

1

总数应该在 SUM() 上,例如:

 string sql = "SELECT bill_no, name_shop, SUM(qty * price) AS [total],dt FROM purchase_stock_entry INNER JOIN purchase_party_name ON purchase_stock_entry.purchase_party_id = purchase_party_name.id GROUP BY bill_no, name_shop;";

或者,您也可以在 GROUP BY 中包含 dt,例如:

  GROUP BY bill_no, name_shop, dt
于 2013-10-19T01:42:38.363 回答