Gets a value indicating whether the primary key of any row in the collection contains the specified value.
[Visual Basic] Overloads Public Function Contains( _ ByVal key As Object _ ) As Boolean [C#] public bool Contains( object key ); [C++] public: bool Contains( Object* key ); [JScript] public function Contains( key : Object ) : Boolean;
true if the collection contains a DataRow with the specified primary key value; otherwise, false.
Exception Type | Condition |
---|---|
MissingPrimaryKeyException | The table doesn't have a primary key. |
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.
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 determine if a RowsCollection object contains a specific value.
[Visual Basic]
Private Sub ColContains() Dim t As DataTable Dim rc As RowsCollection Set t = DataGrid1.DataGridTable.DataTable Set rc = t.Rows If rc.Contains(Edit1.Text) Then Label1.Text = "At least one row contains " & Edit1.Text Else Label1.Text = "No row contains the value in its primary key field" End If End Sub
RowsCollection Class | RowsCollection Members | System.Data Namespace | RowsCollection.Contains Overload List | PrimaryKey | Find