Getting sum of the product of two columns of dataset using Compute method of datatabl
I need to get the sum of Product of two columns of datatable in dataset.
There were no relations in the datatable.
i used the code
dataset.Tables("ABC").Compute("Sum(Price1 * Price2)","")
Where price1 and Price2 are column names in the data table.
i am getting an exception with message
"Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier".
Anybody know the solution, plz reply. its urgent.
Thanks
Re: Getting sum of the product of two columns of dataset using Compute method of datatabl
SUM can only act on one column. You would have to add an extra column with its Expression property set to "Price1 * Price2" and then Compute the SUM of that column.
Re: Getting sum of the product of two columns of dataset using Compute method of datatabl
Re: Getting sum of the product of two columns of dataset using Compute method of data
From Visual Studio Help:
The expression parameter requires an aggregate function. For example, the following is a legal expression:
Count(Quantity)
But this expression is not:
Sum (Quantity * UnitPrice)
If you must perform an operation on two or more columns, you should create a DataColumn, set its Expression property to an appropriate expression, and use an aggregate expression on the resulting column. In that case, given a DataColumn with the name "total," and the Expression property set to:
"Quantity * UnitPrice"
The expression argument for the Compute method would then be:
Sum(total)