How to: Locate a Specific Row in a DataTable
Most applications that consume data need to access specific records that satisfy some kind of criteria. In order to find a particular row in a dataset, you can invoke the Find method of the DataRowCollection object. If the primary key exists, then a DataRow object is returned. If the primary key cannot be found, then a null value is returned.
To find a row in a typed dataset with a primary key value
Call the strongly typed FindBy method that uses the table's primary key to locate a row.
In the following example, the CustomerID column is the primary key of the Customers table, so the generated FindBy method is FindByCustomerID. The example shows how to assign a specific DataRow to a variable using the generated FindBy method.
To find a row in an untyped dataset with a primary key value
The following example shows how to declare a new row called foundRow and assign it the return value of the Find method. If the primary key is found, the contents of column index 1 are displayed in a message box.
To find rows based on the values in any column
Data tables are created with a Select method that returns an array of DataRows based on the expression passed to the Select method. For more information on creating valid expressions, see the "Expression Syntax" section of the page about the Expression property.