I know this is a very old question, and I have a similar situation a few days ago.
The problem is that in my table, approx. 10,000 rows, so the DataTable loopback rows were very slow.
Finally, I found a much faster solution where I make a copy of the DataTable source with the desired results, clear the source text of the DataTable and merge from a temporary DataTable to the original one.
note : instead of searching for Joe , the DataRow is called name You need to search for all records that do not have the name Joe (slightly opposite search path)
Example ( vb.net ):
'Copy all rows into tmpTable whose not contain Joe in name DataRow Dim tmpTable As DataTable = drPerson.Select("name<>'Joe'").CopyToTable 'Clear source DataTable, in Your case dtPerson dtPerson.Clear() 'merge tmpTable into dtPerson (rows whose name not contain Joe) dtPerson.Merge(tmpTable) tmpTable = Nothing
Hope this shorter solution helps someone.
There is c# code (not sure if this is correct, because I used the online converter :():
//Copy all rows into tmpTable whose not contain Joe in name DataRow DataTable tmpTable = drPerson.Select("name<>'Joe'").CopyToTable; //Clear source DataTable, in Your case dtPerson dtPerson.Clear(); //merge tmpTable into dtPerson (rows whose name not contain Joe) dtPerson.Merge(tmpTable); tmpTable = null;
Of course, I used Try/Catch , if there is no result (for example, if your dtPerson does not contain name Joe , it will throw an exception), so you do nothing with your table, it remains unchanged.
nelek Apr 15 '17 at 6:04 on 2017-04-15 06:04
source share