Breyta

Deila með


ForeignKeyConstraint Constructors

Definition

Initializes a new instance of the ForeignKeyConstraint class.

Overloads

ForeignKeyConstraint(DataColumn, DataColumn)

Initializes a new instance of the ForeignKeyConstraint class with the specified parent and child DataColumn objects.

ForeignKeyConstraint(DataColumn[], DataColumn[])

Initializes a new instance of the ForeignKeyConstraint class with the specified arrays of parent and child DataColumn objects.

ForeignKeyConstraint(String, DataColumn, DataColumn)

Initializes a new instance of the ForeignKeyConstraint class with the specified name, parent and child DataColumn objects.

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

Initializes a new instance of the ForeignKeyConstraint class with the specified name, and arrays of parent and child DataColumn objects.

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

This constructor is provided for design time support in the Visual Studio environment. ForeignKeyConstraint objects created by using this constructor must then be added to the collection via AddRange(Constraint[]). Tables and columns with the specified names must exist at the time the method is called, or if BeginInit() has been called prior to calling this constructor, the tables and columns with the specified names must exist at the time that EndInit() is called.

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

This constructor is provided for design time support in the Visual Studio environment. ForeignKeyConstraint objects created by using this constructor must then be added to the collection via AddRange(Constraint[]). Tables and columns with the specified names must exist at the time the method is called, or if BeginInit() has been called prior to calling this constructor, the tables and columns with the specified names must exist at the time that EndInit() is called.

ForeignKeyConstraint(DataColumn, DataColumn)

Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs

Initializes a new instance of the ForeignKeyConstraint class with the specified parent and child DataColumn objects.

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)

Parameters

parentColumn
DataColumn

The parent DataColumn in the constraint.

childColumn
DataColumn

The child DataColumn in the constraint.

Exceptions

One or both of the columns is null.

The columns have different data types.

-Or -

The tables don't belong to the same DataSet.

Examples

The following example creates a new ForeignKeyConstraint, sets some of its properties, and adds it to a DataTable object's 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

Applies to

ForeignKeyConstraint(DataColumn[], DataColumn[])

Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs

Initializes a new instance of the ForeignKeyConstraint class with the specified arrays of parent and child DataColumn objects.

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())

Parameters

parentColumns
DataColumn[]

An array of parent DataColumn in the constraint.

childColumns
DataColumn[]

An array of child DataColumn in the constraint.

Exceptions

One or both of the columns is null.

The columns have different data types.

-Or -

The tables don't belong to the same DataSet.

Examples

The following example creates a new ForeignKeyConstraint, sets some of its properties, and adds it to a DataTable object's 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

Applies to

ForeignKeyConstraint(String, DataColumn, DataColumn)

Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs

Initializes a new instance of the ForeignKeyConstraint class with the specified name, parent and child DataColumn objects.

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)

Parameters

constraintName
String

The name of the constraint.

parentColumn
DataColumn

The parent DataColumn in the constraint.

childColumn
DataColumn

The child DataColumn in the constraint.

Exceptions

One or both of the columns is null.

The columns have different data types.

-Or -

The tables don't belong to the same DataSet.

Examples

The following example creates a new ForeignKeyConstraint, sets some of its properties, and adds it to a DataTable object's 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

Applies to

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

Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs

Initializes a new instance of the ForeignKeyConstraint class with the specified name, and arrays of parent and child DataColumn objects.

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())

Parameters

constraintName
String

The name of the ForeignKeyConstraint. If null or empty string, a default name will be given when added to the constraints collection.

parentColumns
DataColumn[]

An array of parent DataColumn in the constraint.

childColumns
DataColumn[]

An array of child DataColumn in the constraint.

Exceptions

One or both of the columns is null.

The columns have different data types.

-Or -

The tables don't belong to the same DataSet.

Examples

The following example creates a new ForeignKeyConstraint, sets some of its properties, and adds it to a DataTable object's 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

Applies to

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

Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs

This constructor is provided for design time support in the Visual Studio environment. ForeignKeyConstraint objects created by using this constructor must then be added to the collection via AddRange(Constraint[]). Tables and columns with the specified names must exist at the time the method is called, or if BeginInit() has been called prior to calling this constructor, the tables and columns with the specified names must exist at the time that EndInit() is called.

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)

Parameters

constraintName
String

The name of the constraint.

parentTableName
String

The name of the parent DataTable that contains parent DataColumn objects in the constraint.

parentColumnNames
String[]

An array of the names of parent DataColumn objects in the constraint.

childColumnNames
String[]

An array of the names of child DataColumn objects in the constraint.

acceptRejectRule
AcceptRejectRule

One of the AcceptRejectRule values. Possible values include None, Cascade, and Default.

deleteRule
Rule

One of the Rule values to use when a row is deleted. The default is Cascade. Possible values include: None, Cascade, SetNull, SetDefault, and Default.

updateRule
Rule

One of the Rule values to use when a row is updated. The default is Cascade. Possible values include: None, Cascade, SetNull, SetDefault, and Default.

Attributes

Exceptions

One or both of the columns is null.

The columns have different data types.

-Or -

The tables don't belong to the same DataSet.

Applies to

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

Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs
Source:
ForeignKeyConstraint.cs

This constructor is provided for design time support in the Visual Studio environment. ForeignKeyConstraint objects created by using this constructor must then be added to the collection via AddRange(Constraint[]). Tables and columns with the specified names must exist at the time the method is called, or if BeginInit() has been called prior to calling this constructor, the tables and columns with the specified names must exist at the time that EndInit() is called.

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)

Parameters

constraintName
String

The name of the constraint.

parentTableName
String

The name of the parent DataTable that contains parent DataColumn objects in the constraint.

parentTableNamespace
String

The name of the Namespace.

parentColumnNames
String[]

An array of the names of parent DataColumn objects in the constraint.

childColumnNames
String[]

An array of the names of child DataColumn objects in the constraint.

acceptRejectRule
AcceptRejectRule

One of the AcceptRejectRule values. Possible values include None, Cascade, and Default.

deleteRule
Rule

One of the Rule values to use when a row is deleted. The default is Cascade. Possible values include: None, Cascade, SetNull, SetDefault, and Default.

updateRule
Rule

One of the Rule values to use when a row is updated. The default is Cascade. Possible values include: None, Cascade, SetNull, SetDefault, and Default.

Attributes

Exceptions

One or both of the columns is null.

The columns have different data types.

-Or -

The tables don't belong to the same DataSet.

Applies to