Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DataRowCollection.Find Method (Object[])

Gets the row that contains the specified primary key values.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

member Find : 
        keys:Object[] -> DataRow

Parameters

keys
Type: System.Object[]

An array of primary key values to find. The type of the array is Object.

Return Value

Type: System.Data.DataRow
A DataRow object that contains the primary key values specified; otherwise a null value if the primary key value does not exist in the DataRowCollection.

ExceptionCondition
IndexOutOfRangeException

No row corresponds to that index value.

MissingPrimaryKeyException

The table does not have a primary key.

To use the Find method, the DataTable object to which the DataRowCollection object belongs must have at least one column designated as a primary key column. When two or more rows have the same primary key value, then the first row found is returned. This occurs when EnforceConstraints is set to false. See the PrimaryKey property for more information about how to create a PrimaryKey column, or an array of DataColumn objects when the table has more than one primary key.

The following example uses the values of an array to find a specific row in a collection of DataRow objects. The method assumes that a DataTable exists with three primary key columns. After creating an array of the values, the code uses the Find method with the array to get the particular object that you want.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft