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 類別的新執行個體。

public:
 ForeignKeyConstraint(System::Data::DataColumn ^ parentColumn, System::Data::DataColumn ^ childColumn);
public ForeignKeyConstraint (System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);
new System.Data.ForeignKeyConstraint : System.Data.DataColumn * System.Data.DataColumn -> System.Data.ForeignKeyConstraint
Public Sub New (parentColumn As DataColumn, childColumn As DataColumn)

參數

parentColumn
DataColumn

條件約束中的父代 DataColumn

childColumn
DataColumn

條件約束中的子系 DataColumn

例外狀況

資料行的其中一個或者兩個都是 null

資料行具有不同的資料型別。

-或-

資料表不屬於相同的 DataSet

範例

下列範例會建立新的 ForeignKeyConstraint、設定它的一些屬性,並將它新增至 DataTable 物件的 ConstraintCollection

' 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

適用於

ForeignKeyConstraint(DataColumn[], DataColumn[])

來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs

使用父代和子系 ForeignKeyConstraint 物件的指定陣列,初始化 DataColumn 類別的新執行個體。

public:
 ForeignKeyConstraint(cli::array <System::Data::DataColumn ^> ^ parentColumns, cli::array <System::Data::DataColumn ^> ^ childColumns);
public ForeignKeyConstraint (System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);
new System.Data.ForeignKeyConstraint : System.Data.DataColumn[] * System.Data.DataColumn[] -> System.Data.ForeignKeyConstraint
Public Sub New (parentColumns As DataColumn(), childColumns As DataColumn())

參數

parentColumns
DataColumn[]

條件約束中父代 DataColumn 的陣列。

childColumns
DataColumn[]

條件約束中子系 DataColumn 的陣列。

例外狀況

資料行的其中一個或者兩個都是 null

資料行具有不同的資料型別。

-或-

資料表不屬於相同的 DataSet

範例

下列範例會建立新的 ForeignKeyConstraint、設定它的一些屬性,並將它新增至 DataTable 物件的 ConstraintCollection

' 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

適用於

ForeignKeyConstraint(String, DataColumn, DataColumn)

來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs

使用指定名稱以及父代和子系 ForeignKeyConstraint 物件,初始化 DataColumn 類別的新執行個體。

public:
 ForeignKeyConstraint(System::String ^ constraintName, System::Data::DataColumn ^ parentColumn, System::Data::DataColumn ^ childColumn);
public ForeignKeyConstraint (string? constraintName, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);
public ForeignKeyConstraint (string constraintName, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);
new System.Data.ForeignKeyConstraint : string * System.Data.DataColumn * System.Data.DataColumn -> System.Data.ForeignKeyConstraint
Public Sub New (constraintName As String, parentColumn As DataColumn, childColumn As DataColumn)

參數

constraintName
String

條件約束的名稱。

parentColumn
DataColumn

條件約束中的父代 DataColumn

childColumn
DataColumn

條件約束中的子系 DataColumn

例外狀況

資料行的其中一個或者兩個都是 null

資料行具有不同的資料型別。

-或-

資料表不屬於相同的 DataSet

範例

下列範例會建立新的 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 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

適用於

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

來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs

使用指定名稱以及父代和子系 ForeignKeyConstraint 物件的陣列,初始化 DataColumn 類別的新執行個體。

public:
 ForeignKeyConstraint(System::String ^ constraintName, cli::array <System::Data::DataColumn ^> ^ parentColumns, cli::array <System::Data::DataColumn ^> ^ childColumns);
public ForeignKeyConstraint (string? constraintName, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);
public ForeignKeyConstraint (string constraintName, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);
new System.Data.ForeignKeyConstraint : string * System.Data.DataColumn[] * System.Data.DataColumn[] -> System.Data.ForeignKeyConstraint
Public Sub New (constraintName As String, parentColumns As DataColumn(), childColumns As DataColumn())

參數

constraintName
String

ForeignKeyConstraint 的名稱。 如果是 null 或空字串,則在加入至條件約束集合時,會指定預設的名稱。

parentColumns
DataColumn[]

條件約束中父代 DataColumn 的陣列。

childColumns
DataColumn[]

條件約束中子系 DataColumn 的陣列。

例外狀況

資料行的其中一個或者兩個都是 null

資料行具有不同的資料型別。

-或-

資料表不屬於相同的 DataSet

範例

下列範例會建立新的 ForeignKeyConstraint、設定它的一些屬性,並將它新增至 DataTable 物件的 ConstraintCollection

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

適用於

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

來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs

這個建構函式是在 Visual Studio 環境中,針對支援設計階段而提供。 接著必須透過 ForeignKeyConstraint,將使用此建構函式建立的 AddRange(Constraint[]) 物件加入至集合中。 具有指定名稱的資料表和資料行必須在呼叫方法時便存在,如果在呼叫這個建構函式之前便已經呼叫 BeginInit(),則具有指定名稱的資料表和資料行必須在呼叫 EndInit() 時已存在。

public:
 ForeignKeyConstraint(System::String ^ constraintName, System::String ^ parentTableName, cli::array <System::String ^> ^ parentColumnNames, cli::array <System::String ^> ^ childColumnNames, System::Data::AcceptRejectRule acceptRejectRule, System::Data::Rule deleteRule, System::Data::Rule updateRule);
[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);
[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);
[<System.ComponentModel.Browsable(false)>]
new System.Data.ForeignKeyConstraint : string * string * string[] * string[] * System.Data.AcceptRejectRule * System.Data.Rule * System.Data.Rule -> System.Data.ForeignKeyConstraint
Public Sub New (constraintName As String, parentTableName As String, parentColumnNames As String(), childColumnNames As String(), acceptRejectRule As AcceptRejectRule, deleteRule As Rule, updateRule As Rule)

參數

constraintName
String

條件約束的名稱。

parentTableName
String

父代 (Parent) DataTable 的名稱,包含條件約束 (Constraint) 中的父代 DataColumn 物件。

parentColumnNames
String[]

條件約束中的父代 DataColumn 物件的名稱陣列。

childColumnNames
String[]

條件約束中的子系 DataColumn 物件的名稱陣列。

acceptRejectRule
AcceptRejectRule

其中一個 AcceptRejectRule 值。 可能的值包括 NoneCascadeDefault

deleteRule
Rule

其中一個 Rule 值,要在資料列刪除時使用。 預設為 Cascade。 可能的值包括:NoneCascadeSetNullSetDefaultDefault

updateRule
Rule

其中一個 Rule 值,要在資料列更新時使用。 預設為 Cascade。 可能的值包括:NoneCascadeSetNullSetDefaultDefault

屬性

例外狀況

資料行的其中一個或者兩個都是 null

資料行具有不同的資料型別。

-或-

資料表不屬於相同的 DataSet

適用於

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

來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs
來源:
ForeignKeyConstraint.cs

這個建構函式是在 Visual Studio 環境中,針對支援設計階段而提供。 接著必須透過 ForeignKeyConstraint,將使用此建構函式建立的 AddRange(Constraint[]) 物件加入至集合中。 具有指定名稱的資料表和資料行必須在呼叫方法時便存在,如果在呼叫這個建構函式之前便已經呼叫 BeginInit(),則具有指定名稱的資料表和資料行必須在呼叫 EndInit() 時已存在。

public:
 ForeignKeyConstraint(System::String ^ constraintName, System::String ^ parentTableName, System::String ^ parentTableNamespace, cli::array <System::String ^> ^ parentColumnNames, cli::array <System::String ^> ^ childColumnNames, System::Data::AcceptRejectRule acceptRejectRule, System::Data::Rule deleteRule, System::Data::Rule updateRule);
[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);
[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);
[<System.ComponentModel.Browsable(false)>]
new System.Data.ForeignKeyConstraint : string * string * string * string[] * string[] * System.Data.AcceptRejectRule * System.Data.Rule * System.Data.Rule -> System.Data.ForeignKeyConstraint
Public Sub New (constraintName As String, parentTableName As String, parentTableNamespace As String, parentColumnNames As String(), childColumnNames As String(), acceptRejectRule As AcceptRejectRule, deleteRule As Rule, updateRule As Rule)

參數

constraintName
String

條件約束的名稱。

parentTableName
String

父代 (Parent) DataTable 的名稱,包含條件約束 (Constraint) 中的父代 DataColumn 物件。

parentTableNamespace
String

Namespace 的名稱。

parentColumnNames
String[]

條件約束中的父代 DataColumn 物件的名稱陣列。

childColumnNames
String[]

條件約束中的子系 DataColumn 物件的名稱陣列。

acceptRejectRule
AcceptRejectRule

其中一個 AcceptRejectRule 值。 可能的值包括 NoneCascadeDefault

deleteRule
Rule

其中一個 Rule 值,要在資料列刪除時使用。 預設為 Cascade。 可能的值包括:NoneCascadeSetNullSetDefaultDefault

updateRule
Rule

其中一個 Rule 值,要在資料列更新時使用。 預設為 Cascade。 可能的值包括:NoneCascadeSetNullSetDefaultDefault

屬性

例外狀況

資料行的其中一個或者兩個都是 null

資料行具有不同的資料型別。

-或-

資料表不屬於相同的 DataSet

適用於