Gets the row specified by the primary key value.
[Visual Basic] Overloads Public Function Find( _ ByVal key As Object _ ) As DataRow [C#] public DataRow Find( object key ); [C++] public: DataRow* Find( Object* key ); [JScript] public function Find( key : Object ) : DataRow;
A DataRow containing the primary key value specified.
Exception Type | Condition |
---|---|
MissingPrimaryKeyException | The table doesn't have a primary key. |
IndexOutOfRangeException | No row corresponds to the given value. |
To use the Contains 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 primary key column.
The following example uses the Find method to find the primary key value "2" in a collection of DataRow objects. The method returns the specific DataRow object allowing you to change its values, as needed.
[Visual Basic]
Private Sub FindInPKey() Dim t As DataTable Dim foundRow As DataRow Dim rc As RowsCollection Set t = DataGrid1.DataGridTable.DataTable Set rc = t.Rows ' Find the number 2 in the primary key column of the table. Set foundRow = rc.Find(2) ' Display the value of column 1 in a Label control. Label1.Text = foundRow.Item(1) End Sub
RowsCollection Class | RowsCollection Members | System.Data Namespace | RowsCollection.Find Overload List | DataTable | PrimaryKey | Contains