| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ForeignKeyConstraint ClassRepresents 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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 ] |
| Visibility | Name | Parameters | Return Type |
|---|---|---|---|
| public | Equals | ( Object key ) | Boolean |
| public | GetHashCode | ( ) | Int32 |
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.
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.
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
Constraint Constraints ConstraintCollection DataRelation UniqueConstraint
Check out related books at Amazon
© 2000-2008 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 aspxtreme