I would like to get the sum of a column from database but the query returns -1. I have this query:
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))
and the code from C#:
decimal sumaa = 0;
DataTable suma = bonTableAdapter.Suma(DateTime.Now);
foreach (DataRow r in suma.Rows)
{
sumaa += Convert.ToDecimal(r.ItemArray[0]);
}
total column in any record might be null. In that case use this.