System.Data Namespace DataRowCollection Class
Checks whether the primary key Column ( s ) of any row in the collection contains the values specified in the object array.
[ VB ]
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
- keys
- An array of primary key values to test for.
true if the DataRowCollection contains a DataRow with the specified key values; otherwise, false.
To use the Contains method with an array of values, the DataTable object to which the DataRowCollection 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 DataRowCollection object. The example initializes 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.
Private Sub ContainsArray ( )
' this example assumes that the DataTable object contains
' two DataColumn objects designated as primary keys.
Dim myTable As DataTable
Dim myRows As DataRowCollection
' the table has two primary key columns.
Dim arrKeyVals ( 1 ) As Object
myTable = myGrid.DataGridTable.DataTable
myRows = myTable.Rows
arrKeyVals ( 0 ) = "Hello"
arrKeyVals ( 1 ) = "World"
label1.Text = myRows.Contains ( arrKeyVals )
End Sub
DataRowCollection Members DataRowCollection.Contains Overload List PrimaryKey Find