Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9103965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:45:09+00:00 2026-06-17T01:45:09+00:00

I have a Datatable in my VB code that I want to group in

  • 0

I have a Datatable in my VB code that I want to group in two levels (In other words group within another group) and I’m having a problem doing it.

For illustration’s sake, suppose my datatable, MyTable, had columns as follows:

Name1     Name2    Start_Date    End_Date   Var1    Var2

So, supposing I wanted to just group it by, say, Name1, I could do it as follows:

Dim Query1 = From dr as DataRow in MyTable
             Group dr by Name1 = dr.Item("Name1") into Group

And then I could loop through all the records in that group doing something along the lines of:

For Each Grp in Query1
   For Each dr as DataRow in Grp.Rows
      ... do whatever ...
   Next
Next

Now, I would like to create a double group – For Example, suppose I wanted to create an in-memory query that first groups by Start_Date and End_Date and then, WITHIN THAT GROUP, a second grouping by Name1 so I could write a loop along the lines of:

For Each MainGrp in BiggerQuery
   For Each SubGrp in MainGrp
        For Each dr as DataRow in SubGrp .Rows
            ... do whatever ...
        Next
   Next
Next

How would that double-grouped Linq query look in VB? – My first issue is that it seems that VB requires you to name your group Group, which doesn’t allow for double-grouping and secondly, I can’t seem to figure out the query as a whole.

Thanks!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:45:10+00:00Added an answer on June 17, 2026 at 1:45 am
    Dim query = From dr1 As DataRow In MyTable
                Group dr1 By New With { .StartDate = dr1.StartDate, .EndDate = dr1.EndDate } Into g1 = Group
                Select newGroup = (From dr2 As DataRow In g1
                        Group dr2 By dr2.Name1 Into g2 = Group
                        Select g2)
    

    I think it should work, but cannot test it right now.

    EDIT

    There is a nice example of nested grouping on MSDN: http://msdn.microsoft.com/en-us/vstudio/bb737908#grpbynest

    EDIT2

    From dr1 As DataRow In myTable
    Group dr1 By gi1 = New With {.StartDate = dr1.Item("StartDate"), .EndDate = dr1.Item("EndDate")} Into g1 = Group
    Select newGroup = (From dr2 As DataRow In g1
                       Group dr2 By gi2 = dr2.Item("Name1") Into g2 = Group
                       Select g2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataTable with 8 fields. I want to return another DataTable that
I have the following code that serializes a DataTable to XML. StringWriter sw =
hello I have this code that use to sort a datatable. Dim sortingIndex As
I have the following code that fills dataTable1 and dataTable2 with two simple SQL
I have a DataTable and want to group Name, LastName and Comment. The rest
I have the following code that loads an XML file into a datatable (I
I have written a code that searches specific string from database table.what i want
I have a datatable that I want to extract certain information from (only certain
I have a function that returns a datatable, I added a code that will
I have a DataTable that I get from the DB, I want to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.