ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

SelectRows

Wraps the usage of some DataTable.DefaultView properties to return sorted rows filtered on a custom filterexpression. For documentation on what to put in the whereExpression and the orderByExpression, refer to the MSDN documentation of DataTable.DefaultView.RowFilter and DataTable.DefaultView.Sort.

Source

public static DataTable SelectRows(this DataTable dt, string whereExpression, string orderByExpression)
{
	dt.DefaultView.RowFilter = whereExpression;
	dt.DefaultView.Sort = orderByExpression;
	return dt.DefaultView.ToTable();
}

Example

DataTable selection = dt.SelectRows("ID > 10", "Name");

Author: Dan Pettersson

Submitted on: 21 dec. 2009

Language: C#

Type: System.Data.DataTable

Views: 6788