Rule Enumeration
Indicates the action that occurs when a ForeignKeyConstraint is enforced.
[Visual Basic] <Serializable> Public Enum Rule [C#] [Serializable] public enum Rule [C++] [Serializable] __value public enum Rule [JScript] public Serializable enum Rule
Remarks
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.
Members
| Member name | Description |
|---|---|
| Cascade Supported by the .NET Compact Framework. | Delete or update related rows. This is the default. |
| None Supported by the .NET Compact Framework. | No action taken on related rows. |
| SetDefault Supported by the .NET Compact Framework. | Set values in related rows to the value contained in the DefaultValue property. |
| SetNull Supported by the .NET Compact Framework. | Set values in related rows to DBNull. |
Example
[Visual Basic]
' The next line goes into the Declarations section of the module:
' SuppliersProducts is a class derived from DataSet.
Private myDataSet As SuppliersProducts
Private Sub CreateConstraint()
' Declare parent column and child column variables.
Dim pCol As DataColumn
Dim cCol As DataColumn
Dim myFKC As ForeignKeyConstraint
' Set parent and child column variables.
pCol = MyDataSet.Tables("Suppliers").Columns("SupplierID")
cCol = MyDataSet.Tables("Products").Columns("SupplierID")
myFKC = New ForeignKeyConstraint("SupplierFKConstraint", pCol, cCol)
' Set null values when a value is deleted.
myFKC.DeleteRule = Rule.SetNull
myFKC.UpdateRule = Rule.Cascade
myFKC.AcceptRejectRule = AcceptRejectRule.Cascade
' Add the constraint, and set EnforceConstraints to true.
myDataSet.Tables("Products").Constraints.Add(myFKC)
myDataSet.EnforceConstraints = True
End Sub
[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Data
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: System.Data (in System.Data.dll)