Adding columns in a dataset

  • Thread starter Thread starter Steve Wolfie
  • Start date Start date
S

Steve Wolfie

Hello all,

I am trying to figure out how to add up and average a column in my dataset /
datagrid.

the datagrid binds to the dataset and one column contains integers, i wish
to:

add the columns and then divide by total number of columns.

Can someone point me in the right direction? I was thinking about trying to
get a datarowcollection and then add up all the values in the
DataRowCollection.Item(6) and then divide by ds.tables(0).rows.count .. but
i am failing, that is why i am posting..

Thanks
Steve
 
Hi Steve,

You could create a column and assign an Expression to it. DataColumns allow
expression that calculate Average. For example you could create a new column
that calculate average using next kind of code

cTax = New DataColumn
With cTax
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "tax"
.Expression = "Avg(ColumnNameTocalculateAvgOnHere)"
End With
 
Back
Top