NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

RowsCollection.Find (Object)

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;

Parameters

key
The primary key value of the DataRow to find.

Return Value

A DataRow containing the primary key value specified.

Exceptions

Exception Type Condition
MissingPrimaryKeyException The table doesn't have a primary key.
IndexOutOfRangeException No row corresponds to the given value.

Remarks

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.

Example [Visual Basic]

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

See Also

RowsCollection Class | RowsCollection Members | System.Data Namespace | RowsCollection.Find Overload List | DataTable | PrimaryKey | Contains