|
-
Oct 17th, 2006, 03:03 AM
#1
Thread Starter
Junior Member
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
-
Oct 17th, 2006, 03:13 AM
#2
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.
-
Oct 17th, 2006, 03:18 AM
#3
Thread Starter
Junior Member
Re: Getting sum of the product of two columns of dataset using Compute method of datatabl
-
Oct 17th, 2006, 03:29 AM
#4
Member
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|