My Thoughts & Views

Calculate the sum of a column in a dataset

Posted on: February 5, 2008

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)

Advertisements

6 Responses to "Calculate the sum of a column in a dataset"

how can i change the format of the data comlung into 2 decimal only?

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?

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

loop it based on ID and sum the values

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: