CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Posts
    2

    Question Using aggregate function in Datatable select Method

    I'm searching for a way to place an aggregate function in the filter expression of the datatable's select method.

    I thought the syntax would be something like

    dim strexp as string
    strexp = "MAX(columnName)"
    foundrows as datarow()
    foundrows = ds.tablename.select(strexp)

    The error message indicates the filter expression 'MAX(columnName)' cannot be evaluated to a boolean expression.

    Are aggregate expressions supported in the the select method? I searched the online docs without success.

  2. #2
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Using aggregate function in Datatable select Method

    try

    strexp = "Columname = Max(ColumnName)"
    Nicolas Bohemier

  3. #3
    Join Date
    Jun 2008
    Posts
    1

    Angry Re: Using aggregate function in Datatable select Method

    Hi,
    I am also facing the same proble. The said solution works for MAX function but it is not working for sum(ColumnName).

    Code:
        DataSet ds = RepeaterProductInfo.DataSource as DataSet;
        DataRow [] row = ds.Tables[0].Select("Sum(ItemPrice)");
        strReturnValue = row[0][0].ToString();
    But it is throwing Exception {"Filter expression 'Sum(ItemPrice)' does not evaluate to a Boolean term." }


    I also tried following code,

    Code:
        DataSet ds = RepeaterProductInfo.DataSource as DataSet;
        DataRow [] row = ds.Tables[0].Select("ItemPrice = Sum(ItemPrice)");
        strReturnValue = row[0][0].ToString();
    When I try this statement was not able to calculate sum though DataTable contains data.
    Last edited by HanneSThEGreaT; June 17th, 2008 at 12:47 AM.

  4. #4
    Join Date
    May 2008
    Posts
    224

    Re: Using aggregate function in Datatable select Method

    Just a guess here but have you tried using as in the select statement?

    "Select Sum(ItemPrice) as TotalPrice"

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Using aggregate function in Datatable select Method

    shelar hemant, 2 things :
    This thread is 3 years old, in future rather start your own thread.
    It also looks like you are using C#, this is the VB.NET forum

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

Featured