Results 1 to 4 of 4

Thread: Getting sum of the product of two columns of dataset using Compute method of datatabl

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    22

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    22

    Re: Getting sum of the product of two columns of dataset using Compute method of datatabl

    Thanks a Lot.

  4. #4
    Member
    Join Date
    May 2006
    Posts
    47

    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
  •  



Click Here to Expand Forum to Full Width