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

  • Home
  • SEARCH
  • 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 802837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:39:53+00:00 2026-05-14T23:39:53+00:00

I am having some speed issue with my datatables. In this particular case I

  • 0

I am having some speed issue with my datatables. In this particular case I am using it as holder of data, it is never used in GUI or any other scenario that actually uses any of the fancy features.

In my speed trace, this particular constructor was showing up as a heavy user of time when my database is ~40k rows. The main user was set_Item of DataTable.

  protected myclass(DataTable dataTable, DataColumn idColumn)
  {
     this.dataTable = dataTable;
     IdColumn = idColumn ?? this.dataTable.Columns.Add(string.Format("SYS_{0}_SYS", Guid.NewGuid()), Type.GetType("System.Int32"));

     JobIdColumn = this.dataTable.Columns.Add(string.Format("SYS_{0}_SYS", Guid.NewGuid()), Type.GetType("System.Int32"));
     IsNewColumn = this.dataTable.Columns.Add(string.Format("SYS_{0}_SYS", Guid.NewGuid()), Type.GetType("System.Int32"));

     int id = 1;
     foreach (DataRow r in this.dataTable.Rows)
     {
        r[JobIdColumn] = id++;
        r[IsNewColumn] = (r[IdColumn] == null || r[IdColumn].ToString() == string.Empty) ? 1 : 0;
     }

Digging deeper into the trace, it turns out that set_Item calls EndEdit, which brings my thoughts to the transaction support of the DataTable, for which I have no usage for in my scenario.

So my solution to this was to open editing on all of the rows and never close them again.

     _dt.BeginLoadData();
     foreach (DataRow row in _dt.Rows)
         row.BeginEdit();

Is there a better solution? This feels too much like a big giant hack that will eventually come and bite me.

You might suggest that I dont use DataTable at all, but I have already considered that and rejected it due to the amount of effort that would be required to reimplement with a custom class. The main reason it is a datatable is that it is ancient code (.net 1.1 time) and I dont want to spend that much time changing it, and it is also because the original table comes out of a third party component.

The trace data from a test setup (Notice there are NO event listeners whatsoever):

Without opening Edit 100k rows (and 9 columns):

RaiseRowChanging (30.68%) 1204 msec 100k calls
 - get_Item (6.54%) 277msec 900k calls
 - UpdatingCurrent (3.09%) 130msec 900k calls

With opening Edit 100k rows (and 9 columns):

RaiseRowChanging (3.68%) 98 msec 100k calls
 - ...
  • 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-14T23:39:53+00:00Added an answer on May 14, 2026 at 11:39 pm

    Call the BeginLoadData() method on the table.

    Also, you should never call Type.GetType(string).
    Instead, write typeof(string). That alone should make it an order of magnitude faster. (Calling Type.GetType will use reflection to search all loaded assemblies for a type with that name)

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

Sidebar

Related Questions

I'm having some conceptual trouble on figuring out how to best implement this... I
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
The issue I'm currently having is mapping multiple GUI fields to object properties (i.e.
Hey having some trouble trying to maintain transparency on a png when i create
I am having some trouble with the Google Maps API . I have an
We've been having some issues with a SharePoint instance in a test environment. Thankfully
I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I am having some 10 lac records in my single SQL Table. I need
I'm having some issues with producing an int matrix without creating memory leaks. I
I'm having some inheritance issues as I've got a group of inter-related abstract classes

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.