System.Data Namespace DataRowCollection Class
Checks whether the primary key of any row in the collection contains the specified value.
[ VB ]
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
- key
- The value of the primary key to test for.
This method returns only a boolean value: true if the collection contains a DataRow with the specified primary key value; otherwise, false.
The property is read only with no default value.
To use the Contains method, the DataTable object to which the DataRowCollection 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 DataRowCollection object contains a specific value.
Private Sub ColContains ( )
Dim myTable As DataTable
Dim myRows As DataRowCollection
myTable = myGrid.DataGridTable.DataTable
myRows = myTable.Rows
If myRows.Contains ( Edit1.Text ) Then
Label1.Text = "At least one row contains " & Edit1.Text
Else
Label1.Text = "No row contains the specified value"
End If
End Sub
DataRowCollection Members DataRowCollection.Contains Overload List PrimaryKey Find