在WinForms中获取列的总和
本文关键字:获取 WinForms | 更新日期: 2023-09-27 18:23:47
我想从数据库中获得一列的总和,但查询返回-1。我有这个问题:
SELECT SUM(total)
FROM bon
WHERE
(DATEPART(dd, data_adaugare) = DATEPART(dd, @p1))
AND (DATEPART(mm, data_adaugare) = DATEPART(mm, @p1))
AND (DATEPART(yy, data_adaugare) = DATEPART(yy, @p1))
和来自C#的代码:
decimal sumaa = 0;
DataTable suma = bonTableAdapter.Suma(DateTime.Now);
foreach (DataRow r in suma.Rows)
{
sumaa += Convert.ToDecimal(r.ItemArray[0]);
}
您缺少一个+
decimal sumaa = 0;
DataTable suma = bonTableAdapter.Suma(DateTime.Now);
foreach (DataRow r in suma.Rows)
{
sumaa += Convert.ToDecimal(r.ItemArray[0]);
}
SELECT SUM(isnull(total, 0))...