ForeignKeyConstraint クラス
アセンブリ: System.Data (system.data.dll 内)

Public Class ForeignKeyConstraint Inherits Constraint
public class ForeignKeyConstraint : Constraint
public class ForeignKeyConstraint extends Constraint
public class ForeignKeyConstraint extends Constraint

ForeignKeyConstraint は、列内の値を削除または更新したときに実行されるアクションを制限します。この制約は主キー列に使用する必要があります。2 つのテーブル間に親子のリレーションシップがある場合は、親テーブルから値を削除したときに、子行が次のいずれかの影響を受けることがあります。
ForeignKeyConstraint オブジェクトは DataTable の ConstraintCollection に格納されています。このコレクションにアクセスするには Constraints プロパティを使用します。
EnforceConstraints プロパティが true に設定されていない限り、制約は適用されません。
AcceptRejectRule は、DataTable オブジェクトの AcceptChanges メソッドが呼び出されるたびに適用されます。

ForeignKeyConstraint を作成し、そのプロパティの一部を設定し、これを DataTable オブジェクトの ConstraintCollection に追加する例を次に示します。
' 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

System.Data.Constraint
System.Data.ForeignKeyConstraint


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ForeignKeyConstraint クラスのページへのリンク