This documentation is archived and is not being maintained.

DataRowCollection.Find Method (Object[])

Gets the row that contains the specified primary key values.

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

public DataRow Find (
	Object[] keys
public DataRow Find (
	Object[] keys
public function Find (
	keys : Object[]
) : DataRow



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

Return Value

An array of DataRow objects that contain the primary key values specified; otherwise a null value if the primary key values do not exist in the DataRowCollection.

Exception typeCondition


No row corresponds to that index value.


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. 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.

private void FindInMultiPKey(DataTable table)
    // Create an array for the key values to find.
    object[]findTheseVals = new object[3];

    // Set the values of the keys to find.
    findTheseVals[0] = "John";
    findTheseVals[1] = "Smith";
    findTheseVals[2] = "5 Main St.";

    DataRow foundRow = table.Rows.Find(findTheseVals);
    // Display column 1 of the found row.
    if(foundRow != null)

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0