英語で読む

次の方法で共有


ForeignKeyConstraint コンストラクター

定義

ForeignKeyConstraint クラスの新しいインスタンスを初期化します。

オーバーロード

ForeignKeyConstraint(DataColumn, DataColumn)

親子の ForeignKeyConstraint オブジェクトを指定して、DataColumn クラスの新しいインスタンスを初期化します。

ForeignKeyConstraint(DataColumn[], DataColumn[])

親子の ForeignKeyConstraint オブジェクトの配列を指定して、DataColumn クラスの新しいインスタンスを初期化します。

ForeignKeyConstraint(String, DataColumn, DataColumn)

名前と親子の ForeignKeyConstraint オブジェクトを指定して、DataColumn クラスの新しいインスタンスを初期化します。

ForeignKeyConstraint(String, DataColumn[], DataColumn[])

名前と親子の ForeignKeyConstraint オブジェクトの配列を指定して、DataColumn クラスの新しいインスタンスを初期化します。

ForeignKeyConstraint(String, String, String[], String[], AcceptRejectRule, Rule, Rule)

このコンストラクターは、Visual Studio 環境でのデザイン時のサポートのために用意されています。 このコンストラクターを使用して作成した ForeignKeyConstraint オブジェクトは、AddRange(Constraint[]) を使用してコレクションに追加する必要があります。 このメソッドを呼び出したときに、指定した名前のテーブルと列が存在している必要があります。このコンストラクターを呼び出す前に BeginInit() を呼び出した場合は、EndInit() を呼び出したときに、指定した名前のテーブルと列が存在している必要があります。

ForeignKeyConstraint(String, String, String, String[], String[], AcceptRejectRule, Rule, Rule)

このコンストラクターは、Visual Studio 環境でのデザイン時のサポートのために用意されています。 このコンストラクターを使用して作成した ForeignKeyConstraint オブジェクトは、AddRange(Constraint[]) を使用してコレクションに追加する必要があります。 このメソッドを呼び出したときに、指定した名前のテーブルと列が存在している必要があります。このコンストラクターを呼び出す前に BeginInit() を呼び出した場合は、EndInit() を呼び出したときに、指定した名前のテーブルと列が存在している必要があります。

ForeignKeyConstraint(DataColumn, DataColumn)

ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs

親子の ForeignKeyConstraint オブジェクトを指定して、DataColumn クラスの新しいインスタンスを初期化します。

C#
public ForeignKeyConstraint (System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);

パラメーター

parentColumn
DataColumn

制約内の親 DataColumn

childColumn
DataColumn

制約内の子 DataColumn

例外

列の一方または両方が null です。

列のデータ型が異なります。

- または -

テーブルが同じ DataSet に属していません。

次の例では、新ForeignKeyConstraintしい を作成し、そのプロパティの一部を設定し、オブジェクトの ConstraintCollectionDataTable追加します。

VB
' The next line goes into the Declarations section.
' 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 fkConstraint As ForeignKeyConstraint

   ' Set parent and child column variables.
   parentColumn = _
       suppliersProducts.Tables("Suppliers").Columns("SupplierID")
   childColumn = _
       suppliersProducts.Tables("Products").Columns("SupplieriD")
   fkConstraint = New ForeignKeyConstraint(parentColumn, childColumn)

   ' Set various properties of the constraint.
   With fkConstraint
      .ConstraintName = "suppierFKConstraint"
      .DeleteRule = Rule.SetNull
      .UpdateRule = Rule.Cascade
      .AcceptRejectRule = AcceptRejectRule.Cascade
   End With

   ' Add the constraint, and set EnforceConstraints to true.
   suppliersProducts.Tables("Products").Constraints.Add(fkConstraint)
   suppliersProducts.EnforceConstraints = True
End Sub

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ForeignKeyConstraint(DataColumn[], DataColumn[])

ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs

親子の ForeignKeyConstraint オブジェクトの配列を指定して、DataColumn クラスの新しいインスタンスを初期化します。

C#
public ForeignKeyConstraint (System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);

パラメーター

parentColumns
DataColumn[]

制約内の親 DataColumn の配列。

childColumns
DataColumn[]

制約内の子 DataColumn の配列。

例外

列の一方または両方が null です。

列のデータ型が異なります。

- または -

テーブルが同じ DataSet に属していません。

次の例では、新ForeignKeyConstraintしい を作成し、そのプロパティの一部を設定し、オブジェクトの ConstraintCollectionDataTable追加します。

VB
' The next line goes into the Declarations section.
' SuppliersProducts is a class derived from DataSet.
Private suppliersProducts As SuppliersProducts

Private Sub CreateConstraint()
   ' Declare parent column and child column variables.
   Dim parentColumns(1) As DataColumn
   Dim childColumns(1) As DataColumn
   Dim fkConstraint As ForeignKeyConstraint

   ' Set parent and child column variables.
   parentColumns(0) = _
       suppliersProducts.Tables("OrderDetails").Columns("OrderID")
   parentColumns(1) = _
       suppliersProducts.Tables("OrderDetails").Columns("ProductID")
   childColumns(0) = _
       suppliersProducts.Tables("Sales").Columns("OrderID")
   childColumns(1) = _
       suppliersProducts.Tables("Sales").Columns("ProductID")
   fkConstraint = _
       New ForeignKeyConstraint(parentColumns, childColumns)

   ' Set various properties of the constraint.
   With fkConstraint
      .ConstraintName = "ProductSalesOrders"
      .DeleteRule = Rule.SetDefault
      .UpdateRule = Rule.Cascade
      .AcceptRejectRule = AcceptRejectRule.Cascade
   End With

   ' Add the constraint, and set EnforceConstraints to true.
   suppliersProducts.Tables( _
       "OrderDetails").Constraints.Add(fkConstraint)
   suppliersProducts.EnforceConstraints = True
End Sub

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ForeignKeyConstraint(String, DataColumn, DataColumn)

ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs

名前と親子の ForeignKeyConstraint オブジェクトを指定して、DataColumn クラスの新しいインスタンスを初期化します。

C#
public ForeignKeyConstraint (string? constraintName, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);
C#
public ForeignKeyConstraint (string constraintName, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);

パラメーター

constraintName
String

制約の名前。

parentColumn
DataColumn

制約内の親 DataColumn

childColumn
DataColumn

制約内の子 DataColumn

例外

列の一方または両方が null です。

列のデータ型が異なります。

- または -

テーブルが同じ DataSet に属していません。

次の例では、新ForeignKeyConstraintしい を作成し、そのプロパティの一部を設定し、オブジェクトの ConstraintCollectionDataTable追加します。

VB
' 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 various properties of the constraint.
   With fkeyConstraint
      .DeleteRule = Rule.SetNull
      .UpdateRule = Rule.Cascade
      .AcceptRejectRule = AcceptRejectRule.Cascade
   End With

   ' Add the constraint, and set EnforceConstraints to true.
   suppliersProducts.Tables("Products").Constraints.Add(fkeyConstraint)
   suppliersProducts.EnforceConstraints = True
End Sub

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ForeignKeyConstraint(String, DataColumn[], DataColumn[])

ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs

名前と親子の ForeignKeyConstraint オブジェクトの配列を指定して、DataColumn クラスの新しいインスタンスを初期化します。

C#
public ForeignKeyConstraint (string? constraintName, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);
C#
public ForeignKeyConstraint (string constraintName, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);

パラメーター

constraintName
String

ForeignKeyConstraint の名前。 null または空の文字列の場合は、制約コレクションに追加したときに既定の名前が付けられます。

parentColumns
DataColumn[]

制約内の親 DataColumn の配列。

childColumns
DataColumn[]

制約内の子 DataColumn の配列。

例外

列の一方または両方が null です。

列のデータ型が異なります。

- または -

テーブルが同じ DataSet に属していません。

次の例では、新ForeignKeyConstraintしい を作成し、そのプロパティの一部を設定し、オブジェクトの ConstraintCollectionDataTable追加します。

VB
Private Sub CreateConstraint(ByVal suppliersProducts As DataSet)
    ' Declare parent column and child column variables.
    Dim parentColumns(1) As DataColumn
    Dim childColumns(1) As DataColumn
    Dim fkConstraint As ForeignKeyConstraint

    ' Set parent and child column variables.
    parentColumns(0) = _
        suppliersProducts.Tables("OrderDetails").Columns("OrderID")
    parentColumns(1) = _
        suppliersProducts.Tables("OrderDetails").Columns("ProductID")
    childColumns(0) = _
        suppliersProducts.Tables("Sales").Columns("OrderID")
    childColumns(1) = _
        suppliersProducts.Tables("Sales").Columns("ProductID")
    fkConstraint = New ForeignKeyConstraint( _
        "ProductSalesOrders", parentColumns, childColumns)

    ' Set various properties of the constraint.
    With fkConstraint
        .DeleteRule = Rule.SetDefault
        .UpdateRule = Rule.Cascade
        .AcceptRejectRule = AcceptRejectRule.Cascade
    End With

    ' Add the constraint, and set EnforceConstraints to true.
    suppliersProducts.Tables("OrderDetails").Constraints.Add( _
        fkConstraint)
    suppliersProducts.EnforceConstraints = True
End Sub

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ForeignKeyConstraint(String, String, String[], String[], AcceptRejectRule, Rule, Rule)

ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs

このコンストラクターは、Visual Studio 環境でのデザイン時のサポートのために用意されています。 このコンストラクターを使用して作成した ForeignKeyConstraint オブジェクトは、AddRange(Constraint[]) を使用してコレクションに追加する必要があります。 このメソッドを呼び出したときに、指定した名前のテーブルと列が存在している必要があります。このコンストラクターを呼び出す前に BeginInit() を呼び出した場合は、EndInit() を呼び出したときに、指定した名前のテーブルと列が存在している必要があります。

C#
[System.ComponentModel.Browsable(false)]
public ForeignKeyConstraint (string? constraintName, string? parentTableName, string[] parentColumnNames, string[] childColumnNames, System.Data.AcceptRejectRule acceptRejectRule, System.Data.Rule deleteRule, System.Data.Rule updateRule);
C#
[System.ComponentModel.Browsable(false)]
public ForeignKeyConstraint (string constraintName, string parentTableName, string[] parentColumnNames, string[] childColumnNames, System.Data.AcceptRejectRule acceptRejectRule, System.Data.Rule deleteRule, System.Data.Rule updateRule);

パラメーター

constraintName
String

制約の名前。

parentTableName
String

制約内の親 DataTable オブジェクトを格納している親 DataColumn の名前。

parentColumnNames
String[]

制約内の親 DataColumn オブジェクトの名前の配列。

childColumnNames
String[]

制約内の子 DataColumn オブジェクトの名前の配列。

acceptRejectRule
AcceptRejectRule

AcceptRejectRule 値のいずれか 1 つ。 使用できる値は、NoneCascade、および Default です。

deleteRule
Rule

行が削除されたときに使用する Rule 値の 1 つ。 既定値は、Cascade です。 使用できる値は、NoneCascadeSetNullSetDefaultDefault などです。

updateRule
Rule

行が更新されたときに使用する Rule 値の 1 つ。 既定値は、Cascade です。 使用できる値は、NoneCascadeSetNullSetDefaultDefault などです。

属性

例外

列の一方または両方が null です。

列のデータ型が異なります。

- または -

テーブルが同じ DataSet に属していません。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ForeignKeyConstraint(String, String, String, String[], String[], AcceptRejectRule, Rule, Rule)

ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs
ソース:
ForeignKeyConstraint.cs

このコンストラクターは、Visual Studio 環境でのデザイン時のサポートのために用意されています。 このコンストラクターを使用して作成した ForeignKeyConstraint オブジェクトは、AddRange(Constraint[]) を使用してコレクションに追加する必要があります。 このメソッドを呼び出したときに、指定した名前のテーブルと列が存在している必要があります。このコンストラクターを呼び出す前に BeginInit() を呼び出した場合は、EndInit() を呼び出したときに、指定した名前のテーブルと列が存在している必要があります。

C#
[System.ComponentModel.Browsable(false)]
public ForeignKeyConstraint (string? constraintName, string? parentTableName, string? parentTableNamespace, string[] parentColumnNames, string[] childColumnNames, System.Data.AcceptRejectRule acceptRejectRule, System.Data.Rule deleteRule, System.Data.Rule updateRule);
C#
[System.ComponentModel.Browsable(false)]
public ForeignKeyConstraint (string constraintName, string parentTableName, string parentTableNamespace, string[] parentColumnNames, string[] childColumnNames, System.Data.AcceptRejectRule acceptRejectRule, System.Data.Rule deleteRule, System.Data.Rule updateRule);

パラメーター

constraintName
String

制約の名前。

parentTableName
String

制約内の親 DataTable オブジェクトを格納している親 DataColumn の名前。

parentTableNamespace
String

Namespace の名前。

parentColumnNames
String[]

制約内の親 DataColumn オブジェクトの名前の配列。

childColumnNames
String[]

制約内の子 DataColumn オブジェクトの名前の配列。

acceptRejectRule
AcceptRejectRule

AcceptRejectRule 値のいずれか 1 つ。 使用できる値は、NoneCascade、および Default です。

deleteRule
Rule

行が削除されたときに使用する Rule 値の 1 つ。 既定値は、Cascade です。 使用できる値は、NoneCascadeSetNullSetDefaultDefault などです。

updateRule
Rule

行が更新されたときに使用する Rule 値の 1 つ。 既定値は、Cascade です。 使用できる値は、NoneCascadeSetNullSetDefaultDefault などです。

属性

例外

列の一方または両方が null です。

列のデータ型が異なります。

- または -

テーブルが同じ DataSet に属していません。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1