asp.net.ph

DataRowCollection.Contains Method ( Object [ ] )

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

Parameters

keys
An array of primary key values to test for.

Return Value

true if the DataRowCollection contains a DataRow with the specified key values; otherwise, false.

Exceptions


Exception Type Condition
MissingPrimaryKeyException Occurs when the table does not have a primary key.

Remarks

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.

Example

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
See Also

DataRowCollection Members   DataRowCollection.Contains Overload List   PrimaryKey   Find Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph