asp.net.ph

ConstraintCollection.CanRemove Method

System.Data Namespace   ConstraintCollection Class


Indicates if a Constraint can be removed.

[ VB ]
Public Function CanRemove ( _
   ByVal constraint As Constraint _
) As Boolean

[ C# ]
public bool CanRemove (
   Constraint constraint
);

[ C++ ]
public: bool CanRemove (
   Constraint* constraint
);

[ JScript ]
public function CanRemove (
   constraint : Constraint
) : Boolean

Parameters

constraint
The Constraint to be tested for removal from the collection.

Return Value

Generates an exception if the Constraint can not be removed from collection. Otherwise, true if the Constraint can be removed.

Exceptions


Exception Type Condition
Exception Occurs when the Constraint can not be removed.

Remarks

When a DataRelation is added to a DataSet, a ForeignKeyConstraint and UniqueConstraint are added automatically to the parent table and the child table. The UniqueConstraint is applied to the parent table's primary key column, and the ForeignKeyConstraint is applied to the child table's foreign key column. In that case, attempting to remove the UniqueConstraint will cause an exception to be thrown because the ForeignKeyConstraint must be removed first. To avoid this, use the CanRemove to determine if a UniqueConstraint can be removed.

Example

The following example uses the CanRemove to determine if a Constraint can be removed, before attempting to remove it.

private void TryRemove ( DataSet myDataSet ) {
   try {
      DataTable t = myDataSet.Tables [ "Customers" ];
      Constraint c = t.Constraints [ 0 ];
      Response.Write ( "Can remove? " + t.Constraints.CanRemove ( c ) );
   }
   catch ( Exception e ) {
      Response.Write ( e.Source + e.Message );
   }
}
  C# VB

See Also

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