none
combine dataRow[] RRS feed

  • Question

  • hello i want to sum my dataRows in this manner

    [ID]      [Value]            TO --->       [ID]         [Value]
    2             1.0                                    1               8.0
    1             4.0                                    2               1.0
    3             2.0                                    3               4.0
    3             2.0 
    1             3.0
    1             1.0

    Any Suggestion?
    Thursday, July 19, 2007 8:15 PM

Answers

  • You could use Compute method of the DataTable to calculate this information. Another way is to use expression column in DataTable
    Friday, July 20, 2007 3:34 AM
    Moderator
  • For example to calculate sum based on ID and using Compute method, your code would look like

     

    Dim totalValue as Double

    totalValue = MyDataTable.Compute("Sum(Value)","ID=2")

     

    You need to replace ID value inside of expression to get sum or specific ID

     

    Friday, July 20, 2007 10:18 AM
    Moderator

All replies

  • You could use Compute method of the DataTable to calculate this information. Another way is to use expression column in DataTable
    Friday, July 20, 2007 3:34 AM
    Moderator
  • Do you have an example where i can base on?

     

    Thanks

    Friday, July 20, 2007 5:01 AM
  • For example to calculate sum based on ID and using Compute method, your code would look like

     

    Dim totalValue as Double

    totalValue = MyDataTable.Compute("Sum(Value)","ID=2")

     

    You need to replace ID value inside of expression to get sum or specific ID

     

    Friday, July 20, 2007 10:18 AM
    Moderator
  • hmm great.
    But how can i handle if i don't know what id may come up?
    I mean prob an example which will handle general case.
    Friday, July 20, 2007 2:01 PM
  • Then you concatenate ID value to the filter string, like

     

    Dim totalValue as Double

    totalValue = MyDataTable.Compute("Sum(Value)","ID=" & MyValueHere)

    Monday, July 23, 2007 10:36 AM
    Moderator