DataRowCollection.Contains Method (Object())
Gets a value that indicates whether the primary key columns of any row in the collection contain the values specified in the object array.
Assembly: System.Data (in System.Data.dll)
To use the Contains method with an array of values, the DataTable object to which the DataRowCollection object belongs must have an array of columns designated as primary keys. See the PrimaryKey property for more information about how to create an array of primary key columns. The number of array elements must correspond to the number of primary key columns in the DataTable.
The following Visual Basic 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, and 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. ' The table has two primary key columns. Dim arrKeyVals(1) As Object Dim table As DataTable = CType(DataGrid1.DataSource, DataTable) Dim rowCollection As DataRowCollection = table.Rows arrKeyVals(0) = "Hello" arrKeyVals(1) = "World" label1.Text = rowCollection.Contains(arrKeyVals).ToString() End Sub
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.