Posts
1150
Comments
891
Trackbacks
1
.NET - DataTable.Select performance

This method allows you to set filter and sorting criteria and pull all rows that meet them from a DataTable.  However, if you have a large number of rows, the performance nose-dives dramatically.

For instance, with a data table of about 400,000 rows, to do a certain number of iterations of a method that used DataTable.Select took approximately 20 minutes.  By ordering the data and doing some checks on each row within a for loop to make sure it met the criteria I needed, the same number of iterations took less than 1 second.

So, be careful when using DataTable.Select (and make sure you index it, etc. regardless).  If you have a large number of rows, you might find that writing more code (which, depending on your view of for loops, may look messy) performs significantly better.

posted on Wednesday, April 13, 2005 11:09 AM Print
Comments
Gravatar
# re: .NET - DataTable.Select performance
mansatan
8/14/2009 8:52 AM
great advice, i thought ms guys must have done it the best way possible, so i blindly used Select to search for a pattern since Rows.Find needs an exact value but after reading your post i tried it out and now the performance is several times faster.
cool! :)

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 2 and 1 and type the answer here: