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
- constraint
- The Constraint to be tested for removal from the collection.
Generates an exception if the Constraint can not be removed from collection. Otherwise, true if the Constraint can be removed.
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.
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 );
}
}
Private Sub TryRemove ( myDataSet As DataSet )
Try
Dim t As DataTable = myDataSet.Tables ( "Customers" )
Dim c As Constraint = t.Constraints ( 0 )
Response.Write ( "Can remove? " & t.Constraints.CanRemove ( c ).ToString ( ) )
Catch e As Exception
Response.Write ( e.Source + e.Message )
End Try
End Sub |
|
C# |
VB |
ConstraintCollection Members