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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:08:59+00:00 2026-05-24T16:08:59+00:00

I have defined a DataTable by adding typed columns. I expect the DataTable to

  • 0

I have defined a DataTable by adding typed columns. I expect the DataTable to range between 1 million to 3 million rows.

I am using Microsoft’s TextFieldParser (because it supports multiple fixed width formats, well kind of, via a Peek method), to populate the rows of the DataTable.

I would like to have some sort of operation that either copies rows from the DataTable into a mirrored SQL table.

If I populate the entire DataTable and then use SqlAdapter and SqlCommandBuilder to update the SQL table as mentioned here I run out of memory.

How can I accomplish this?

  • 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-24T16:08:59+00:00Added an answer on May 24, 2026 at 4:08 pm

    It is not recommended to use DataTable for 1 M of rows, you can simply create new SqlComand for INSERT and make all table fields to be parameters and run this command in the loop.

    But if you already have written a lot of code with DataTable, you may consider it as a buffer, and have the following workaround:

    1) as far as you read data rows, check how many have been already read so far

    2) as soon as you get 10K rows you execute DataTable.Update();

    (you may call this parameter as a buffer_size and put somewhere in configuration to avoid hardcoding)

    3) then you clean up all data in the DataTable, by calling

    DataTable.Clear(); 
    DataTable.AcceptChanges();
    

    4) you continue reading data from file, loop repeats


    In addition, it is hard to make a general suggestions without knowing the structure of your file and purpose of the application, I only answered the question how to avoid “out of memory” when using very large datasets. But I also recommend to consider all possible options to avoid using .NET data tables as intermediate storage of data and process file directly with all possible means that SQL server provide, such as

    1) BULK INSERT – http://msdn.microsoft.com/en-us/library/ms188365.aspx

    2) bcp utility – http://msdn.microsoft.com/en-us/library/ms162802.aspx

    3) MS SQL Intergartion Services – http://msdn.microsoft.com/en-us/library/ms141026.aspx

    bulk insert operations using any of those commands and tools can be initiated from .NET.

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

Sidebar

Related Questions

I have a DataGridView bound to a DataTable that has 1+16 columns defined as
I have two datatable, while adding rows in second datatable, I want to first
If I have an ObjectDataSource defined at design time, can I get a DataTable
I have a DataSet with a DataTable having the columns Number and Description. I
I have a user defined type, which is a datatable in an SqlServer database.
I have a DataTable which is bound to DataGridView . DataTable has several columns
Is it possible to get records between a Timespan from a DataTable using the
Let's say we have a simple table defined as: <p:dataTable value=#{testBean.dummyStringData} var=data> <p:column> <p:commandLink
I have an xml file and I am loading it in DataTable using DataSet.ReadXML.
I have defined a custom Sharepoint list for special attributes related to a software

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.