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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:42:19+00:00 2026-05-11T15:42:19+00:00

Update: Here’s a similar question Suppose I have a DataTable with a few thousand

  • 0

Update: Here’s a similar question


Suppose I have a DataTable with a few thousand DataRows in it.

I’d like to break up the table into chunks of smaller rows for processing.

I thought C#3’s improved ability to work with data might help.

This is the skeleton I have so far:

DataTable Table = GetTonsOfData();  // Chunks should be any IEnumerable<Chunk> type var Chunks = ChunkifyTableIntoSmallerChunksSomehow; // ** help here! **  foreach(var Chunk in Chunks) {    // Chunk should be any IEnumerable<DataRow> type    ProcessChunk(Chunk); } 

Any suggestions on what should replace ChunkifyTableIntoSmallerChunksSomehow?

I’m really interested in how someone would do this with access C#3 tools. If attempting to apply these tools is inappropriate, please explain!


Update 3 (revised chunking as I really want tables, not ienumerables; going with an extension method–thanks Jacob):

Final implementation:

Extension method to handle the chunking:

public static class HarenExtensions {     public static IEnumerable<DataTable> Chunkify(this DataTable table, int chunkSize)     {         for (int i = 0; i < table.Rows.Count; i += chunkSize)         {             DataTable Chunk = table.Clone();              foreach (DataRow Row in table.Select().Skip(i).Take(chunkSize))             {                 Chunk.ImportRow(Row);             }              yield return Chunk;         }     } } 

Example consumer of that extension method, with sample output from an ad hoc test:

class Program {     static void Main(string[] args)     {         DataTable Table = GetTonsOfData();          foreach (DataTable Chunk in Table.Chunkify(100))         {             Console.WriteLine('{0} - {1}', Chunk.Rows[0][0], Chunk.Rows[Chunk.Rows.Count - 1][0]);         }          Console.ReadLine();     }      static DataTable GetTonsOfData()     {         DataTable Table = new DataTable();         Table.Columns.Add(new DataColumn());          for (int i = 0; i < 1000; i++)         {             DataRow Row = Table.NewRow();             Row[0] = i;              Table.Rows.Add(Row);         }          return Table;     } } 
  • 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. 2026-05-11T15:42:20+00:00Added an answer on May 11, 2026 at 3:42 pm

    This seems like an ideal use-case for Linq’s Skip and Take methods, depending on what you want to achieve with the chunking. This is completely untested, never entered in an IDE code, but your method might look something like this.

    private List<List<DataRow>> ChunkifyTable(DataTable table, int chunkSize) {     List<List<DataRow>> chunks = new List<List<DataRow>>();     for (int i = 0; i < table.Rows.Count / chunkSize; i++)     {         chunks.Add(table.Rows.Skip(i * chunkSize).Take(chunkSize).ToList());     }          return chunks; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
Update I summarized the question and its answers here My objective is to detect
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
Here is the updated question: the current query is doing something like: $sql1 =
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
How do I update a Gridview on a aspx page from a webmethod? Here
we're dealing with a very slow update statement in an Oracle project. Here's a
How can I represent the following in XSD. <price-update> <![CDATA[ arbitrary data goes here
Update: here is an MSDN article How to: Make Thread-Safe Calls to Windows Forms
UPDATE: Here's my solution (inspired by accepted answer): function log(msg, values) { if(config.log ==

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.