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. Web Development
  3. ASP.NET
  4. GroupBy in datatable??

GroupBy in datatable??

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nethelpquestion
6 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.
  • P Offline
    P Offline
    playout
    wrote on last edited by
    #1

    Hi, Is there a way to use groupBy in a datatable? I need to group some vaules in a column. I cannot use a sql query, as I am munipulating the data in the datatable for a gridview. I know there are no function/class available in asp.net, but maybe someone knows where to find something on the net, or had the same problem as me.

    V I 2 Replies Last reply
    0
    • P playout

      Hi, Is there a way to use groupBy in a datatable? I need to group some vaules in a column. I cannot use a sql query, as I am munipulating the data in the datatable for a gridview. I know there are no function/class available in asp.net, but maybe someone knows where to find something on the net, or had the same problem as me.

      V Offline
      V Offline
      VenkataRamana Gali
      wrote on last edited by
      #2

      Hi, Yes, we can use aggrigate functions for DataTable. Here is the sample code. You can use group by also. DataTable table = dataSet.Tables["Orders"]; object sumObject; sumObject = table.Compute("Sum(Total)", "EmpID = 5"); enjoy...

      regards GV Ramana

      P 1 Reply Last reply
      0
      • V VenkataRamana Gali

        Hi, Yes, we can use aggrigate functions for DataTable. Here is the sample code. You can use group by also. DataTable table = dataSet.Tables["Orders"]; object sumObject; sumObject = table.Compute("Sum(Total)", "EmpID = 5"); enjoy...

        regards GV Ramana

        P Offline
        P Offline
        playout
        wrote on last edited by
        #3

        Thanks Ramana. Now if I want to group on a string, how would I do that? My columns in datatable are F2 and F3. I want to group by F2, where F3 is the primary key.

        1 Reply Last reply
        0
        • P playout

          Hi, Is there a way to use groupBy in a datatable? I need to group some vaules in a column. I cannot use a sql query, as I am munipulating the data in the datatable for a gridview. I know there are no function/class available in asp.net, but maybe someone knows where to find something on the net, or had the same problem as me.

          I Offline
          I Offline
          Imran Khan Pathan
          wrote on last edited by
          #4

          Try this code DataRow[] dr=DataTable.Select("gruopBy ColumnName"); Home this will help u? Best regard Pathan

          GOD HELP THOSE WHO HELP THEMSELVES

          P 1 Reply Last reply
          0
          • I Imran Khan Pathan

            Try this code DataRow[] dr=DataTable.Select("gruopBy ColumnName"); Home this will help u? Best regard Pathan

            GOD HELP THOSE WHO HELP THEMSELVES

            P Offline
            P Offline
            playout
            wrote on last edited by
            #5

            Hi Pathan, It looks like something that can help me, but where do I use it? Where I fill my new datatable, or from the current datatable?

            I 1 Reply Last reply
            0
            • P playout

              Hi Pathan, It looks like something that can help me, but where do I use it? Where I fill my new datatable, or from the current datatable?

              I Offline
              I Offline
              Imran Khan Pathan
              wrote on last edited by
              #6

              HI. By this code You will get array of datarow, After that You can Import this array row in new table. Like this dataTable NewTable; Datarow dr[]=datatabale.Select("groupBy columnName"); foreach(datarow dr1 in dr) { NewTable.ImportRow(dr1); } Best Regard Pathan

              GOD HELP THOSE WHO HELP THEMSELVES

              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