Using Aggregate functions in DataView filters
Posted
by Shrewd Demon
on Stack Overflow
See other posts from Stack Overflow
or by Shrewd Demon
Published on 2010-05-24T10:37:42Z
Indexed on
2010/05/24
10:41 UTC
Read the original article
Hit count: 1002
hi,
i have a DataTable that has a column ("Profit"). What i want is to get the Sum of all the values in this table. I tried to do this in the following manner...
DataTable dsTemp = new DataTable();
dsTemp.Columns.Add("Profit");
DataRow dr = null;
dr = dsTemp.NewRow();
dr["Profit"] = 100;
dsTemp.Rows.Add(dr);
dr = dsTemp.NewRow();
dr["Profit"] = 200;
dsTemp.Rows.Add(dr);
DataView dvTotal = dsTemp.DefaultView;
dvTotal.RowFilter = " SUM ( Profit ) ";
DataTable dt = dvTotal.ToTable();
But i get an error while applying the filter... how can i get the Sum of the Profit column in a variable
thank you...
© Stack Overflow or respective owner