Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Use Gruop By in Datatable.Compute() method

Use Gruop By in Datatable.Compute() method

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naunt
    wrote on last edited by
    #1

    Dear All, I have the follow data in my Dataset1.Table(0)

    col1 Col2 Col3 Col4 Col5 Qty
    SS 111 SIN C 20 114
    SS 111 SIN C 40 28
    SS 111 SIN S 20 165
    SS 111 SIN S 40 189

    I want to SUM(Qty) those are same color The result will like below

    SSUM 111 SGSIN 20 279 (row1 + row3)
    SSUM 111 SGSIN 40 217 (row2 + row4)

    I don’t want to loop and sum row by row. Is there any DataTable Method to get my result? If I use like this how will be my result?

    Dataset1.Table(0).Compute(“Sum(Qty)”,”Group by Col1,Col2,Col3,Col5”)

    Please, any suggestion for the best way. Thanks and Best Regards

    T M 2 Replies Last reply
    0
    • N Naunt

      Dear All, I have the follow data in my Dataset1.Table(0)

      col1 Col2 Col3 Col4 Col5 Qty
      SS 111 SIN C 20 114
      SS 111 SIN C 40 28
      SS 111 SIN S 20 165
      SS 111 SIN S 40 189

      I want to SUM(Qty) those are same color The result will like below

      SSUM 111 SGSIN 20 279 (row1 + row3)
      SSUM 111 SGSIN 40 217 (row2 + row4)

      I don’t want to loop and sum row by row. Is there any DataTable Method to get my result? If I use like this how will be my result?

      Dataset1.Table(0).Compute(“Sum(Qty)”,”Group by Col1,Col2,Col3,Col5”)

      Please, any suggestion for the best way. Thanks and Best Regards

      T Offline
      T Offline
      TweakBird
      wrote on last edited by
      #2

      Have a look on this Helper[^] Link2[^]

      1 Reply Last reply
      0
      • N Naunt

        Dear All, I have the follow data in my Dataset1.Table(0)

        col1 Col2 Col3 Col4 Col5 Qty
        SS 111 SIN C 20 114
        SS 111 SIN C 40 28
        SS 111 SIN S 20 165
        SS 111 SIN S 40 189

        I want to SUM(Qty) those are same color The result will like below

        SSUM 111 SGSIN 20 279 (row1 + row3)
        SSUM 111 SGSIN 40 217 (row2 + row4)

        I don’t want to loop and sum row by row. Is there any DataTable Method to get my result? If I use like this how will be my result?

        Dataset1.Table(0).Compute(“Sum(Qty)”,”Group by Col1,Col2,Col3,Col5”)

        Please, any suggestion for the best way. Thanks and Best Regards

        M Offline
        M Offline
        Manish Choudhary NET expert
        wrote on last edited by
        #3

        Try this code: You have to select each group from the table. Declare a new DataTable Temp, now select the group values or distinct value in this datatable by following code( I am using C# language.)

        DataTable TEMP = new DataTable();
        TEMP=Dataset1.Table(0).DefaultView.ToTable(true,"Col4");

        Now the TEMP table will have following values in it- 1. C 2. S Now you can use loop and

        DataSet.Compute("Sum(Qty)","Col4='"+TEMP.Rows[location][0].ToString()+"'")

        method for data stored in TEMP. You can not use DataSet.Compute() method for multiple values as it is a single value function. :-D :-D :-D :-D :-D :-D For any further clearification please mail me at cybosoft@gmail.com

        C#, VB.NET,ASP.NET DEVELOPER

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups