Problem : Calculate the sum of a column in a dataset
Solution :
After filling the dataset from your query you can calculate the sum of a numeric column.
Dataset's DataTable provides a default method called Compute through which you can perform any aggregate function based operation on columns in a DataTable.
Suppose you have
1. Column : Salary
2. DataSet : dsData
3. DataTable Name : Payroll
Then
dsData.Tables("Payroll").Compute("SUM(Salary)", String.Empty)
Gives the sum of that column.
Compute accepts two arguments : 1. Expression (Any aggregate Expression)
2. Filter (Any Filtering option, here String.Empty means no filter value)
Subscribe to:
Post Comments (Atom)
3 comments:
how can i change the format of the data comlung into 2 decimal only?
i have two datasets, say firstDS, secondDS.
in both the datasets, have two columns,say ID,value.
need to sum the value depends on the same ID in the both datasets, how can do?
loop it based on ID and sum the values
Post a Comment