Export (0) Print
Expand All

DataRowCollection.Contains Method

Gets a value indicating whether the primary key column(s) of any row in the collection contains the specified value.

Overload List

Gets a value indicating whether the primary key of any row in the collection contains the specified value.

Supported by the .NET Compact Framework.

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

Gets a value indicating whether the primary key column(s) of any row in the collection contains the values specified in the object array.

Supported by the .NET Compact Framework.

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

Example

[Visual Basic] The following example uses the Contains method to find a particular row in a DataRowCollection 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] Note   This example shows how to use one of the overloaded versions of Contains. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub ContainsArray()
   ' This example assumes that the DataTable object contains at two
   ' DataColumn objects designated as primary keys.
   Dim myTable As DataTable
   Dim rc As DataRowCollection
   ' The table has two primary key columns.
   Dim arrKeyVals(1) As Object
   myTable = CType(DataGrid1.DataSource, DataTable)
   rc = myTable.Rows
   arrKeyVals(0) = "Hello"
   arrKeyVals(1) = "World"
   label1.Text = rc.Contains(arrKeyVals).ToString()
End Sub

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataRowCollection Class | DataRowCollection Members | System.Data Namespace

Show:
© 2014 Microsoft