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 3940456
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:25:15+00:00 2026-05-20T00:25:15+00:00

I have a datatable which contains a load of dates. I wanted to group

  • 0

I have a datatable which contains a load of dates. I wanted to group these by date and give each row a count.

I have managed to do this by dong the following:

 IEnumerable query = from row in stats.AsEnumerable()
                     group row by row.Field<string>("date") into grp
                     select new { Date = grp.Key, Count = grp.Count(t => t["date"] != null) };

(where “stats” is the datatable)

I can see from debugging that this brings back the values all grouped as I need, but now I need to loop them and get each date and count.

My problem is I don’t know how to retrieve the values!

I have a foreach loop

foreach (var rw  in query)
{
   string date = rw.Date; // <---- this is my problem?
}

I don’t know what type my Ienumerable is to be able to reference the values in it!

So my question is how can I retrieve each date and count for each row by doing similar to the above?

I hope this makes sense!

  • 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-05-20T00:25:16+00:00Added an answer on May 20, 2026 at 12:25 am

    This link on my blog should help you
    http://www.matlus.com/linq-group-by-finding-duplicates/

    Essentially your type is an anonymous type so you can’t reference it as a type but you can access the properties like you’re trying to do.

    I think I see your issue. If you’re trying to return it from a method, you should define a type and reuturn it like shown below:

    public IEnumerable<MyType> GetQuery()
    {
    
      var query = from row in stats.AsEnumerable()
                        group row by row.Field<string>("date") into grp
                        select new { Date = grp.Key, Count = grp.Count(t => t["date"] != null) }; 
    
      foreach (var rw  in query)
      {
         yield return new MyType(rw.Date, rw.Count);
      }
    }
    

    declare your “query” variable using “var” as shown above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datatable which contains all these records (see SQL query). Instead of
I have a DataTable which I select from database (Well, these data cross several
I have a form which contains a DataGridView, a BindingSource, a DataTable, and a
I have a Business Object which contains a DataTable among other properties. I pass
I have a DataTable which contains data in this format. I want to convert
How to do following scenario: I have some DataTable which contains for example some
I have a datatable which is filled from the resultset of a 1 row
I have a datatable which contains following data as SrNo Roll Name 1 1
I have a simple data table which contains dynamic form text fields. Each field
i have a datatable which contains InvalidCodes. Before uploading the data to database(data is

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.