views:

37

answers:

1

Hi I have a datatable which has an amount column & a status column. I want to sum only those rows who have status '1'. How to do this ? I am summing the column via datatable Compute method. Please advice.

+5  A: 

dataTable.Compute("sum(amount)", "status = 1")

thelost
Hi, that was quick. Thanks thelost ! I am having a little problem. My status datacolumn is a boolean. I am having error "Object cannot be cast from dbNull to other types"CompTab.Columns.Add(new DataColumn("IsRep", typeof(bool)));CompTabRow["IsRep"] = true;.......total = Convert.ToDecimal(CompTab.Compute("SUM(Share)", "IsRep=false"));
Popo
Edit: Sorry, my bad. I found there were no innitial rows inside datatable matching the criteria.
Popo