Performing Arithmetic on DataTable Columns

Discussion in 'ASP .Net' started by George Durzi, Jun 7, 2004.

  1. George Durzi

    George Durzi Guest

    I have a DataTable with only one DataColumn of type float. I need to
    calculate the Max value that in any of the DataRows, and this DataColumn.

    I noticed the DataColumn has an Expression property:
    http://msdn.microsoft.com/library/d...fSystemDataDataColumnClassExpressionTopic.asp

    However, it seems that I would end up having to create a new DataColumn,
    call it MaxVal or something, and populate it for every row.

    Is there a cleaner way?
     
    George Durzi, Jun 7, 2004
    #1
    1. Advertising

  2. George Durzi

    George Durzi Guest

    Nevermind, I discovered the Compute method.

    float flMax =
    (float)m_dsSegments.Tables["Calculations"].Compute("Max(Score)",
    string.Empty);



    "George Durzi" <> wrote in message
    news:...
    > I have a DataTable with only one DataColumn of type float. I need to
    > calculate the Max value that in any of the DataRows, and this DataColumn.
    >
    > I noticed the DataColumn has an Expression property:
    >

    http://msdn.microsoft.com/library/d...fSystemDataDataColumnClassExpressionTopic.asp
    >
    > However, it seems that I would end up having to create a new DataColumn,
    > call it MaxVal or something, and populate it for every row.
    >
    > Is there a cleaner way?
    >
    >
     
    George Durzi, Jun 7, 2004
    #2
    1. Advertising

  3. If your contents are bound to a dataset why don't you just use the dataset
    ds.Tables[0].Compute("Max(["+strColumnName+"])",String.Empty)

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "George Durzi" <> wrote in message
    news:...
    >I have a DataTable with only one DataColumn of type float. I need to
    > calculate the Max value that in any of the DataRows, and this DataColumn.
    >
    > I noticed the DataColumn has an Expression property:
    > http://msdn.microsoft.com/library/d...fSystemDataDataColumnClassExpressionTopic.asp
    >
    > However, it seems that I would end up having to create a new DataColumn,
    > call it MaxVal or something, and populate it for every row.
    >
    > Is there a cleaner way?
    >
    >
     
    Alvin Bruney [MVP], Jun 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe
    Replies:
    1
    Views:
    8,403
    Kevin Spencer
    Aug 15, 2003
  2. Fredrik Rodin

    Sort a datatable and create a new datatable

    Fredrik Rodin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    9,100
    paul.mariotti
    Sep 28, 2007
  3. =?Utf-8?B?Qmx1ZWZsb3dlcg==?=

    Casting DataTable to class inherit from DataTable

    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=, Apr 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,021
    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=
    Apr 2, 2004
  4. jg
    Replies:
    1
    Views:
    751
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Aug 17, 2004
  5. joshc
    Replies:
    5
    Views:
    583
    Keith Thompson
    Mar 31, 2005
Loading...

Share This Page