Rule Enumeration

Indicates the action that occurs when a ForeignKeyConstraint is enforced.

Namespace: System.Data
Assembly: System.Data (in

public enum class Rule
public enum Rule
public enum Rule

 Member nameDescription
Supported by the .NET Compact FrameworkCascadeDelete or update related rows. This is the default. 
Supported by the .NET Compact FrameworkNoneNo action taken on related rows. 
Supported by the .NET Compact FrameworkSetDefaultSet values in related rows to the value contained in the DefaultValue property. 
Supported by the .NET Compact FrameworkSetNullSet values in related rows to DBNull

The Rule values are set to the UpdateRule and the DeleteRule properties of a ForeignKeyConstraint object found in a DataTable object's ConstraintCollection.

The Rule values determine the action that occurs when a value in a column is either deleted or updated. Of the two, deleting a value is the more critical and demanding of attention when setting a rule.

In the case where a value is deleted, Cascade specifies that all rows containing that value are also deleted. SetNull specifies that values in all child columns are set to null values. SetDefault specifies that all child columns be set to the default value for the column. None specifies that no action will occur, but exceptions are generated.

In the case where a value is updated, Cascade specifies that all child columns are likewise updated with the new value. SetNull specifies that all child columns be set to null values. SetDefault specifies that all child column values be set to the default value. None specifies that no action be taken, but exceptions are generated.

Constraints on a DataSet are not enforced unless the EnforceConstraints property is true.

When the AcceptChanges method is called, the AcceptRejectRule further determines what action occurs.

' The next line goes into the Declarations section of the module:
' SuppliersProducts is a class derived from DataSet.
Private suppliersProducts As SuppliersProducts

Private Sub CreateConstraint()
    ' Declare parent column and child column variables.
    Dim parentColumn As DataColumn
    Dim childColumn As DataColumn
    Dim fkeyConstraint As ForeignKeyConstraint

    ' Set parent and child column variables.
    parentColumn = suppliersProducts.Tables("Suppliers").Columns("SupplierID")
    childColumn = suppliersProducts.Tables("Products").Columns("SupplierID")
    fkeyConstraint = New ForeignKeyConstraint( _
        "SupplierFKConstraint", parentColumn, childColumn)

    ' Set null values when a value is deleted.
    fkeyConstraint.DeleteRule = Rule.SetNull
    fkeyConstraint.UpdateRule = Rule.Cascade
    fkeyConstraint.AcceptRejectRule = AcceptRejectRule.Cascade

    ' Add the constraint, and set EnforceConstraints to true.
    suppliersProducts.EnforceConstraints = True
End Sub

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0