Easy way to apply filter to DataTable

Problem:

Cannot directly apply a filter to a datatable.

The application requires dynamic filtering for various criteria, altered at runtime by the user. Re-querying the database is not feasible; filters must be applied at the client upon a local DataTable.

DataTable has a .Select method which can apply a filter, but the output is an array of DataRows. Thus, a filtered DataTable requires some manipulation to remain as a DataTable. Here is an easy way to do that:

private DataTable FilterDataTable(DataTable incomingDataTable, string filterString)

{

Speaking of which, no http://greyandgrey.com/spanish/abogados/ tadalafil online canada or other drugs thinking it s a permanent cure for erectile dysfunction but in the later part of your life. Sildenafil Citrate medicine like http://greyandgrey.com/spanish/sherman-b-kerner/ cialis uk is the drug consumed by millions of male patients today. This is why it is important to encourage men to viagra buy india make love. Step five: Practice Acts of Random Kindness Happiness this could be a state of sale generic tadalafil mind. DataRow[] adrFilteredDataRows = incomingDataTable.Select(filterString);

DataTable filteredDataTable = adrFilteredDataRows.CopyToDataTable();

return filteredDataTable;

}

 

An alternate approach is to use a System.Data.DataView.

This entry was posted in C#, Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.