ForeignKeyConstraint 建構函式

定義

初始化 ForeignKeyConstraint 類別的新執行個體。

多載

名稱 Description
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.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.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.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.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
來源:
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

包含約束中父DataTable物件的父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
來源:
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

包含約束中父DataTable物件的父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一個。

適用於