Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove rows from huge data table without iterating it?

Tags:

c#

asp.net

I have a DataTable available with me which contains thousands of rows. There is a column called EmpID which is containing '0' for some of the rows. I want to remove them from my current DataTable and want to create a new correct DataTable. I cannot go row by row checking it since it contains huge amount of data. Give me a suggestion to overcome this problem.

like image 350
NayeemKhan Avatar asked Jan 28 '11 12:01

NayeemKhan


1 Answers

the best way would be to filter it at source (if possible) - so if you are creating it from a db, exclude all 0 values in your sql query itself using a where

starting .net 2.0, ms enhanced the filtering logic on the datatable to a great extent. so if you used the dataview (on top of your datatable) and added the where clause in there and added some sort of runtime indexes on this field, it would give you the desired results without looping over all records

like image 142
Raj Avatar answered Sep 29 '22 03:09

Raj