Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
C#
List<DataRow> list = dtxml.AsEnumerable().Take(r).ToList();
foreach (DataRow dRremove in list)
{
    dtxml.Rows.Remove(dRremove);
    dtxml.AcceptChanges();
}

The above datatable deletion take much more time. How to reduce time consuming.
Posted
Updated 4-Jan-12 11:12am
v2
Comments
senguptaamlan 4-Jan-12 7:34am    
please, explain a bit more...
K N R 4-Jan-12 7:39am    
I have 10000 records in a datatable and i am deleting those records. When ever i am deleting those records that's taking a too much time to delete. so could you please tell me if there is a any better way to delete the records quickly
incaunu 4-Jan-12 7:55am    
Try calling the dtxml.AcceptChanges(); after the loop is done.

Your .AcceptChanges() call should not be performed after every action. This is causing overhead on every iteration that only should be done once at the end of the process. Move it outside of and directly after your foreach loop.
 
Share this answer
 
Comments
Wendelius 4-Jan-12 17:11pm    
That should help a lot.
Another possibility could be that you define a query which returns the rows you want to have in the result and using a dataview you create a new datatableFor example something like (just a sketch):
C#
DataView testView = new DataView(dtxml);
testView.RowFilter = "...";
DataTable testTable = TestView.ToTable("NewTable");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900