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;
true if the RowsCollection contains a DataRow with the specified key values; otherwise, false.
Exception Type | Condition |
---|---|
MissingPrimaryKeyException | The table doesn't have a primary key. |
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.
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
RowsCollection Class | RowsCollection Members | System.Data Namespace | RowsCollection.Contains Overload List | PrimaryKey | Find