1
Answer

Remove rows from a datatable worked very slow

Guido Leibbrand

Guido Leibbrand

10y
1.4k
1
Hi together,

at first i get a big datatable from a oracle database (>100.000 items).
In a second step i want remove items by filtercritera.

But the way i remove the items worked very slow. Perhaps you can help me to find a faster way ;)

Why i do it on this way: There is no way to get performant a smaler datatable direct from oracle.

I hope there is a way to remove items fast from a datatable.


Here the sourcecode:

//Select useable items (works very fast)
var useable = dataTable.Select("(COLUMN1 IN (1,3,7)) AND ISNULL(DATECOLUMN1,'2014-07-22 18:04:35Z') > '2014-07-16 18:04:35Z'");
//List for the Items to delete
var listToDelete = new List<DataSet.TESTDATARow>();

//Check is datarow "useable" (works very slow 120.000 items over 40 sec.)
foreach (var rowItem in dataTable)
{
    var found = useable.Contains(rowItem);
    if (!found)
    {
        listToDelete.Add(rowItem);
    }
}

//Remove items from dataTable (works very fast)
foreach (var logisticDataRow in listToDelete)
{
    dataTable.Rows.Remove(logisticDataRow);
}


i use .Net 4.0
VS 2010

cheers
Guido

Attachment: beispielfuerpost.zip

Answers (1)