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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:37:26+00:00 2026-06-03T01:37:26+00:00

I have a DataTable thats filling up with 360,000 rows of SQL Data (this

  • 0

I have a DataTable thats filling up with 360,000 rows of SQL Data (this is intended). However this runs into OOM issues.

This is what I have, however, i’m not sure on how to handle everthing after the last interval of 1000. Or maybe there is a better way

int catchInt = 0;
string combineWhereClause = string.Empty;

for (int i = 0; i < ThousandLoopTable.Rows.Count; i++)
{
    catchInt++;
    combineWhereClause = combineWhereClause + 
                        "','" + 
                         ThousandLoopTable.Rows[i].ItemArray[0].ToString();

    if (catchInt >= 1000)
    {
        catchInt = 0;
        combineWhereClause = combineWhereClause.TrimStart('\'');
        combineWhereClause = combineWhereClause.TrimStart(',');

        Directory.CreateDirectory(ExportDirectory);
        SQLProcessing.SQLProcessor.MasterSqlConnection = 
            SQLProcessing.SQLProcessor.OpenMasterSqlConnection(SQLServer);
        DataTable dtTable = 
            SQLProcessing.SQLProcessor.QueryDataTable(sql_selectionquery);
        for (int m = 0; m < dtTable.Rows.Count; m++)
        {
            string FileName = dtTable.Rows[m].ItemArray[0].ToString() + ".txt";
            string OCR = dtTable.Rows[m].ItemArray[1].ToString();
            File.AppendAllText(ExportDirectory + "\\" + FileName, OCR);

        }

        combineWhereClause = string.Empty;
    }
}

So for example if there is 3120 rows, this will do 3000, but will not do the last 120. However, i’m not sure how to handle the last 120 because I don’t really want to do that in the for loop do I?

  • 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-03T01:37:27+00:00Added an answer on June 3, 2026 at 1:37 am

    There are probably better ways to handle data (see other answers), but I think this is what you need for your current approach:

    Don’t reset catchInt for every batch. Instead, initialise it as 1 and let it run as a counter for the whole operation. Then change the if to:

    if (catchInt % 1000 == 0 || catchInt == ThousandLoopTable.Rows.Count)
    {
        // Execute your batch
    }
    

    This uses the Modulus operator to identify when catchInt is divisible by 1000.

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

Sidebar

Related Questions

I have a datatable that contains rows of transaction data for multiple users. Each
DataTable.Rows.Add() adds a row to the data table. However, how does it handle the
I have a gridview I am populating it by creating a datatable filling that
I have a DataTable that I manually created and loaded with data using C#.
I have 3 collection datatable that shows in this below Month: January ID NAME
I have a untyped DataTable that looks like this (srcTbl): date col_1 col_2 ...
I have a DataTable object that contains all the data for a Table visualization.
I have a primefaces datatable: <p:dataTable id=idCrawledDataTable var=crawledData value=#{crawlerCorpusTreatmentBean.crawledDataModel} rowKey=#{crawledData.id} rows=10 scrollable=true scrollHeight=300 selection=#{crawlerCorpusTreatmentBean.crawledData}
I have a DataTable that is filled in from an SQL query to a
I have a datatable with some rows I need to insert that datatable in

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.