FindRows
DataRowView[]rows
= DataView.FindRows(ObjectsortKey
); DataRowView[] rows = DataView.FindRows(Object[]sortKey
);
Returns an array with every DataRowView
object
that matches a specified search expression in a given
DataView
. If no match is found, FindRows( )
returns an empty array.
The FindRows( )
method requires exact matches. You
can’t perform a partial match (for example, by
supplying just a first name for the ContactName
).
Object
sortKey
Object[]
sortKey
The sortKey
specifies that value you are
searching for. The data type you use must match the data type of the
column used for the search criteria. If you create a sort expression
that incorporates information from multiple columns, you must use the
overloaded version of the FindRows( )
method that
accepts an array with search values for all columns. These search
values must use the same order as the columns in the sort expression.
The following code snippet searches for an exact match of the
Country
field and displays the information for all
matching rows:
DataView view = new DataView(ds.Tables["Customers"]); view.Sort = "Country"; DataRowView[] rows = view.FindRows("Germany"); if (rows.Length == 0) { Console.WriteLine("No match found."); } else { foreach (DataRowView row in rows) { Console.WriteLine(row["CustomerID"].ToString() + " is a match."); } }
To use the FindRows( )
method, you must define a
sort order for a DataView
, either by setting the
RowFilter
property or the
ApplyDefaultSort
property. If you want to search a
unique column, you can use the Find( )
method
instead of the FindRows( )
method for slightly
easier coding.
The case-sensitivity of search values for the FindRows( )
method is determined by the
CaseSensitive
property of the underlying
DataTable
.