473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why is DataTable.Clear() so slow?

I fill a DataTable with search results, which take a very long time if
I first clear it. The values come from an object and I map them into
the corresponding table columns. I may have 65000 results. I iterate
through them, create a new row, fill it, and add it to the DataTable
for each interation. This works fine on the first search.

Before each search, I call DataTable.Clear() and do the above process.
Every search after the first one is extremely slow to fill the
DataTable. However, if I comment out the Clear() line, performance
doesn't suffer. Is there another way I can clean this table for each
search?

Why is .Clear() such a performance hit?

Thanks,
Brett

Jun 21 '06 #1
4 7653
Hello Brett,

Why not just create new DataTable instead of creating existed?

BR> I fill a DataTable with search results, which take a very long time
BR> if I first clear it. The values come from an object and I map them
BR> into the corresponding table columns. I may have 65000 results. I
BR> iterate through them, create a new row, fill it, and add it to the
BR> DataTable for each interation. This works fine on the first
BR> search.
BR>
BR> Before each search, I call DataTable.Clear() and do the above
BR> process. Every search after the first one is extremely slow to fill
BR> the DataTable. However, if I comment out the Clear() line,
BR> performance doesn't suffer. Is there another way I can clean this
BR> table for each search?
BR>
BR> Why is .Clear() such a performance hit?
BR>
BR> Thanks,
BR> Brett
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jun 21 '06 #2
Hi Michael,
Why not just create new DataTable instead of creating existed?


What exactly is Clear() doing?

Why is recreating the table better than just clearing it? There's a
big difference there and I'm not sure why performance suffers so
greatly after Clear()ing.

Thanks,
Brett

Jun 21 '06 #3
Hello Brett,

Use Reflector to look at DataTable.Clear code.
It performs a lot of job - check parent constrains, remove rows, clear indexes.

For the big tables you can end up with creating new dataTable is more quick
way than clearing existed

BR> Hi Michael,
BR>
Why not just create new DataTable instead of creating existed?

BR> What exactly is Clear() doing?
BR>
BR> Why is recreating the table better than just clearing it? There's a
BR> big difference there and I'm not sure why performance suffers so
BR> greatly after Clear()ing.
BR>
BR> Thanks,
BR> Brett
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jun 22 '06 #4

Michael Nemtsev wrote:
Hello Brett,

Use Reflector to look at DataTable.Clear code.
It performs a lot of job - check parent constrains, remove rows, clear indexes.

For the big tables you can end up with creating new dataTable is more quick
way than clearing existed


It's not the Clear() that is such a problem. It's once I do the
Clear() then start adding back that is the problem.

Brett

Jun 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
I'm using a DataTable in my application. I am able to load rows into the DataTable quickly. What's puzzling me, however, is that when I update a set of cells in the DataTable, the update is really...
2
by: VM | last post by:
When I display data to a Windows datagrid I usually fill the underlying table (in another class) and then, once it contains all the data, I attach it to the grid. But there are some processes that...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
1
by: Simon | last post by:
Hi All, I have a DataGrid bound to a DataTable. Every once in a while I need to refresh the data in the table so that the updated data is displayed in the DataGrid. Here's how I am attempting...
0
by: Flack | last post by:
I have pasted at the end of this message a small sample program I whipped up to do some testing. It's a form with a datagrid and two buttons. Each button clears the dataTable that is the source...
4
by: oopman2002 | last post by:
I have created a DataSet DataTable which is comprised of data from a number of sources. The resultant datatable is about 500,000 records and writing them out one at a time takes forever. Does...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
8
by: cj | last post by:
I have a program to display queries to a SQL db. I type my query in a textbox and click a button and the results display in a datagrid. I could use either dataset or datatable to read the data in...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.