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.Contains (Object[])

Gets a value indicating if the DataRow with the specified primary key values exists.

[Visual Basic]
Overloads Public Function Contains( _
   ByVal keys() As Object _
) As Boolean
[C#]
public bool Contains(
   object[] keys
);
[C++]
public: bool Contains(
   Object* keys[]
);
[JScript]
public function Contains(
   keys : Object[]
) : Boolean;

Parameters

keys
An array of primary key values to test for.

Return Value

true if the RowsCollection contains a DataRow with the specified key values; otherwise, false.

Exceptions

Exception Type Condition
MissingPrimaryKeyException The table doesn't have a primary key.

Remarks

To use the Contains method with an array of values, the DataTable object to which the RowsCollection object belongs must have at an array of columns designated as a primary keys. See the PrimaryKey property for details on creating an array of primary key columns. The number of array elements must correspond to the number of primary key columns in the DataTable.

Once you have determined that a row contains the specified value, you can use the Find method to return the specific DataRow object with the value.

Example [Visual Basic]

The following example uses the Contains method to find a particular row in a RowsCollection object. The example creates an array of values, one element for each primary key in the table, then passes the array to the method to return a true or false.

[Visual Basic]

Private Sub ContainsArray()
' This example assumes that the DataTable object contains at two
' DataColumn objects designated as primary keys.
   Dim t As DataTable
   Dim rc As RowsCollection
   ' The table has two primary key columns.
   Dim arrKeyVals(1) As Object
   Set t = DataGrid1.DataGridTable.DataTable
   Set rc = t.Rows
   arrKeyVals(0) = "Hello"
   arrKeyVals(1) = "World"
   label1.Text = rc.Contains(arrKeyVals)
End Sub

See Also

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