Rule Enumeration
Indicates the action that occurs when a ForeignKeyConstraint is enforced.
Assembly: System.Data (in System.Data.dll)
| Member name | Description | |
|---|---|---|
![]() ![]() | None | No action taken on related rows. |
![]() ![]() | Cascade | Delete or update related rows. This is the default. |
![]() ![]() | SetNull | Set values in related rows to DBNull. |
![]() ![]() | SetDefault | Set values in related rows to the value contained in the DefaultValue property. |
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.Tables("Products").Constraints.Add(fkeyConstraint) suppliersProducts.EnforceConstraints = True End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
