asp.net.ph

DataRowCollection.Contains Method ( Object )

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

Parameters

key
The value of the primary key to test for.

Return Value

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.

Exceptions


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

Remarks

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.

Example

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