Gets the row containing the specified primary key values.
[Visual Basic] Overloads Public Function Find( _ ByVal keys() As Object _ ) As DataRow [C#] public DataRow Find( object[] keys ); [C++] public: DataRow* Find( Object* keys[] ); [JScript] public function Find( keys : Object[] ) : DataRow;
The found DataRow.
Exception Type | Condition |
---|---|
MissingPrimaryKeyException | The table doesn't have a primary key. |
IndexOutOfRangeException | No row corresponds to that index value. |
To use the Find method, the DataTable object to which the RowsCollection object belongs to must have at least one column designated as a Primary Key column. See the PrimaryKey property for details on creating 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 presumes 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 desired.
[Visual Basic]
Private Sub FindInMultiPKey() Dim foundRow As DataRow Dim rc As RowsCollection ' Create an array for the key values to find. Dim findTheseVals(2) As Object ' Set the values of the keys to find. findTheseVals(0) = "John" findTheseVals(1) = "Smith" findTheseVals(2) = "5 Main St." Set rc = DataGrid1.DataGridTable.DataTable.Rows Set foundRow = rc.Find(findTheseVals) ' Display column 1 of the found row. Label1.Text = foundRow(1) End Sub
RowsCollection Class | RowsCollection Members | System.Data Namespace | RowsCollection.Find Overload List | DataTable | PrimaryKey | Contains