asp.net.ph

Rule Enumeration

System.Data Namespace


Indicates the action that occurs when a ForeignKeyConstraint is enforced.

Members


Member Name Description
Cascade Delete or update related rows. This is the default.
None No action taken on related rows.
SetDefault Set values in related rows to the value contained in the DefaultValue property.
SetNull Set values in related rows to DBNull.

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.

Example

   ' the next line goes into the Declarations section of the module:

   ' suppliersProducts is a class derived from DataSet.
Private myDataSet As SuppliersProducts
Private Sub SetConstraint ( )

   ' 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 ( "SupplierFkConst", 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 ( "Suppliers" ).Constraints.Add ( myFKC )
   myDataSet.EnforceConstraints = True
End Sub
See Also

Constraints   ForeignKeyConstraint 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