Wednesday, September 23, 2009

Filter DataTable and Sort

public static DataTable FilterDataTable(DataTable dataTable, string filterQuery, string sortQuery)
{
DataTable table = new DataTable();
try
{
DataRow[] rowArray = dataTable.Select(filterQuery, sortQuery);
table = dataTable.Clone();
foreach (DataRow row in rowArray)
{
table.ImportRow(row);
}
}
catch
{
table = dataTable.Clone();
}
return table;
}

No comments: