asp.net.ph

ForeignKeyConstraint Class

System.Data Namespace


Represents an action restriction enforced on a set of columns in a primary key/foreign key relationship when a value or row is either deleted or updated.

ForeignKeyConstraint Class Members

Collapse   Constructors

Visibility Constructor Parameters
public ForeignKeyConstraint ( DataColumn parentColumn , DataColumn childColumn )
public ForeignKeyConstraint ( String constraintName , DataColumn parentColumn , DataColumn childColumn )
public ForeignKeyConstraint ( DataColumn parentColumns , DataColumn childColumns )
public ForeignKeyConstraint ( String constraintName , DataColumn parentColumns , DataColumn childColumns )
public ForeignKeyConstraint ( String constraintName , String parentTableName , String parentColumnNames , String childColumnNames , AcceptRejectRule acceptRejectRule , Rule deleteRule , Rule updateRule )
public ForeignKeyConstraint ( String constraintName , String parentTableName , String parentTableNamespace , String parentColumnNames , String childColumnNames , AcceptRejectRule acceptRejectRule , Rule deleteRule , Rule updateRule )

Collapse   Properties

Visibility Name Value Type Accessibility
public AcceptRejectRule AcceptRejectRule [ Get , Set ]
public Columns DataColumn [ Get ]
public DeleteRule Rule [ Get , Set ]
public RelatedColumns DataColumn [ Get ]
public RelatedTable DataTable [ Get ]
public Table DataTable [ Get ]
public UpdateRule Rule [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
public Equals ( Object key ) Boolean
public GetHashCode ( ) Int32

Remarks

A ForeignKeyConstraint restricts the action performed when a value in a column ( or columns ) is either deleted or updated. Such a constraint is intended to be used with primary key columns. In a parent/child relationship between two tables, deleting a value from the parent table can affect the child rows in one of the following ways.

  • the child rows can also be deleted ( a cascading action ).
  • the values in the child column ( or columns ) can be set to null values.
  • the values in the child column ( or columns ) can be set to default values.
  • An exception can be generated.

ForeignKeyConstraint objects are contained in the ConstraintCollection of a DataTable, which is accessed through the Constraints property.

Constraints are not enforced unless the EnforceConstraints property is set to true.

The AcceptRejectRule is enforced whenever a DataTable object' s AcceptChanges method is invoked.

Example

The following example initializes a ForeignKeyConstraint, sets various of its properties, and adds it to a DataTable object' s ConstraintCollection.

[ VB ]' 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

Constraint   Constraints   ConstraintCollection   DataRelation   UniqueConstraint 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