DataRelation Constructors

Definition

Initializes a new instance of the DataRelation class.

Overloads

DataRelation(String, DataColumn, DataColumn)

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

DataRelation(String, DataColumn[], DataColumn[])

Initializes a new instance of the DataRelation class using the specified DataRelation name and matched arrays of parent and child DataColumn objects.

DataRelation(String, DataColumn, DataColumn, Boolean)

Initializes a new instance of the DataRelation class using the specified name, parent and child DataColumn objects, and a value that indicates whether to create constraints.

DataRelation(String, DataColumn[], DataColumn[], Boolean)

Initializes a new instance of the DataRelation class using the specified name, matched arrays of parent and child DataColumn objects, and value that indicates whether to create constraints.

DataRelation(String, String, String, String[], String[], Boolean)

This constructor is provided for design time support in the Visual Studio environment.

DataRelation(String, String, String, String, String, String[], String[], Boolean)

This constructor is provided for design time support in the Visual Studio environment.

DataRelation(String, DataColumn, DataColumn)

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

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

Parameters

relationName
String

The name of the DataRelation. If null or an empty string (""), a default name will be given when the created object is added to the DataRelationCollection.

parentColumn
DataColumn

The parent DataColumn in the relationship.

childColumn
DataColumn

The child DataColumn in the relationship.

Exceptions

One or both of the DataColumn objects contains null.

The columns have different data types

-Or-

The tables do not belong to the same DataSet.

Examples

The following example creates a new DataRelation and adds it to the DataRelationCollection of a DataSet.

private void CreateRelation()
{
    // Code to get the DataSet not shown here.
    // Get the DataColumn objects from two DataTable
    // objects in a DataSet.
    DataColumn[] parentCols = new DataColumn[]
        {DataSet1.Tables["Customers"].Columns["CustID"],
        DataSet1.Tables["Customers"].Columns["OrdID"]};
    DataColumn[] childCols= new DataColumn[]
        {DataSet1.Tables["Orders"].Columns["CustID"],
        DataSet1.Tables["Orders"].Columns["OrdID"]};

    // Create DataRelation.
    DataRelation CustOrderRel = new DataRelation(
        "CustomersOrders", parentCols, childCols);

    // Add the relation to the DataSet.
    DataSet1.Relations.Add(CustOrderRel);
}

 Private Sub CreateRelation()
    ' Code to get the DataSet not shown here.
    ' Get the DataColumn objects from two DataTable 
    ' objects in a DataSet.
    Dim parentCols As DataColumn() = _
        {DataSet1.Tables("Customers").Columns("CustID"), _
        DataSet1.Tables("Customers").Columns("OrdID")}
    Dim childCols As DataColumn() = _
        {DataSet1.Tables("Orders").Columns("CustID"), _
        DataSet1.Tables("Orders").Columns("OrdID")}

    ' Create DataRelation.
    Dim CustOrderRel As New DataRelation( _
        "CustomersOrders", parentCols, childCols)

    ' Add the relation to the DataSet.
    DataSet1.Relations.Add(CustOrderRel)
End Sub

See also

Applies to

DataRelation(String, DataColumn[], DataColumn[])

Initializes a new instance of the DataRelation class using the specified DataRelation name and matched arrays of parent and child DataColumn objects.

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

Parameters

relationName
String

The name of the relation. If null or an empty string (""), a default name will be given when the created object is added to the DataRelationCollection.

parentColumns
DataColumn[]

An array of parent DataColumn objects.

childColumns
DataColumn[]

An array of child DataColumn objects.

Exceptions

One or both of the DataColumn objects contains null.

The DataColumn objects have different data types

-Or-

One or both of the arrays are not composed of distinct columns from the same table.

-Or-

The tables do not belong to the same DataSet.

Examples

The following example creates a new DataRelation and adds it to the DataRelationCollection of a DataSet.

Private Sub CreateRelation()
    ' Code to get the DataSet not shown here.
    ' Get the DataColumn objects from two DataTable 
    ' objects in a DataSet.
    Dim parentColumns() As DataColumn
    Dim childColumns() As DataColumn
    parentColumns(0) = DataSet1.Tables( _
        "Customers").Columns("CustID")
    parentColumns(1) = DataSet1.Tables( _
        "Customers").Columns("OrdID")
 
    childColumns(0) = DataSet1.Tables( _
        "Orders").Columns("CustID")
    childColumns(1) = DataSet1.Tables( _
        "Orders").Columns("OrdID")

    ' Create DataRelation.
    Dim CustOrderRel As New DataRelation( _
        "CustomersOrders", parentColumns, childColumns)

    ' Add the relation to the DataSet.
    DataSet1.Relations.Add(CustOrderRel)
End Sub

See also

Applies to

DataRelation(String, DataColumn, DataColumn, Boolean)

Initializes a new instance of the DataRelation class using the specified name, parent and child DataColumn objects, and a value that indicates whether to create constraints.

public:
 DataRelation(System::String ^ relationName, System::Data::DataColumn ^ parentColumn, System::Data::DataColumn ^ childColumn, bool createConstraints);
public DataRelation (string? relationName, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn, bool createConstraints);
public DataRelation (string relationName, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn, bool createConstraints);
new System.Data.DataRelation : string * System.Data.DataColumn * System.Data.DataColumn * bool -> System.Data.DataRelation
Public Sub New (relationName As String, parentColumn As DataColumn, childColumn As DataColumn, createConstraints As Boolean)

Parameters

relationName
String

The name of the relation. If null or an empty string (""), a default name will be given when the created object is added to the DataRelationCollection.

parentColumn
DataColumn

The parent DataColumn in the relation.

childColumn
DataColumn

The child DataColumn in the relation.

createConstraints
Boolean

A value that indicates whether constraints are created. true, if constraints are created. Otherwise, false.

Exceptions

One or both of the DataColumn objects contains null.

The columns have different data types

-Or-

The tables do not belong to the same DataSet.

Examples

The following example creates a new DataRelation and adds it to the DataRelationCollection of a DataSet.


 Private Sub CreateRelation()
    ' Code to get the DataSet not shown here.
    ' Get the DataColumn objects from two DataTable 
    ' objects in a DataSet.
    Dim parentColumn As DataColumn = DataSet1.Tables( _
        "Customers").Columns("CustID")
    Dim childColumn As DataColumn = _
        DataSet1.Tables("Orders").Columns("CustID")

    ' Create DataRelation.
    Dim bConstraints As Boolean = True
    Dim customerOrdersRelation As DataRelation = _
        New DataRelation("CustomersOrders", _
        parentColumn, childColumn, bConstraints)

    ' Add the relation to the DataSet.
    DataSet1.Relations.Add(customerOrdersRelation)
End Sub

See also

Applies to

DataRelation(String, DataColumn[], DataColumn[], Boolean)

Initializes a new instance of the DataRelation class using the specified name, matched arrays of parent and child DataColumn objects, and value that indicates whether to create constraints.

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

Parameters

relationName
String

The name of the relation. If null or an empty string (""), a default name will be given when the created object is added to the DataRelationCollection.

parentColumns
DataColumn[]

An array of parent DataColumn objects.

childColumns
DataColumn[]

An array of child DataColumn objects.

createConstraints
Boolean

A value that indicates whether to create constraints. true, if constraints are created. Otherwise, false.

Exceptions

One or both of the DataColumn objects is null.

The columns have different data types

-Or-

The tables do not belong to the same DataSet.

Examples

The following example creates a new DataRelation and adds it to the DataRelationCollection of a DataSet.

Private Sub CreateRelation()
    ' Code to get the DataSet not shown here.
    ' Get the DataColumn objects from two DataTable 
    ' objects in a DataSet.
    Dim parentColumns() As DataColumn
    Dim childColumns() As DataColumn
    parentColumns(0) = DataSet1.Tables( _
        "Customers").Columns("CustID")
    parentColumns(1) = DataSet1.Tables( _
        "Customers").Columns("OrdID")
 
    childColumns(0) = DataSet1.Tables( _
        "Orders").Columns("CustID")
    childColumns(1) = DataSet1.Tables( _
        "Orders").Columns("OrdID")
 
    Dim bConstraints As Boolean = True
    ' Create DataRelation.
    Dim CustOrderRel As New DataRelation( _
        "CustomersOrders", parentColumns, childColumns,  _
        bConstraints)

    ' Add the relation to the DataSet.
    DataSet1.Relations.Add(CustOrderRel)
End Sub

See also

Applies to

DataRelation(String, String, String, String[], String[], Boolean)

This constructor is provided for design time support in the Visual Studio environment.

public:
 DataRelation(System::String ^ relationName, System::String ^ parentTableName, System::String ^ childTableName, cli::array <System::String ^> ^ parentColumnNames, cli::array <System::String ^> ^ childColumnNames, bool nested);
[System.ComponentModel.Browsable(false)]
public DataRelation (string relationName, string? parentTableName, string? childTableName, string[]? parentColumnNames, string[]? childColumnNames, bool nested);
[System.ComponentModel.Browsable(false)]
public DataRelation (string relationName, string parentTableName, string childTableName, string[] parentColumnNames, string[] childColumnNames, bool nested);
[<System.ComponentModel.Browsable(false)>]
new System.Data.DataRelation : string * string * string * string[] * string[] * bool -> System.Data.DataRelation
Public Sub New (relationName As String, parentTableName As String, childTableName As String, parentColumnNames As String(), childColumnNames As String(), nested As Boolean)

Parameters

relationName
String

The name of the relation. If null or an empty string (""), a default name will be given when the created object is added to the DataRelationCollection.

parentTableName
String

The name of the DataTable that is the parent table of the relation.

childTableName
String

The name of the DataTable that is the child table of the relation.

parentColumnNames
String[]

An array of DataColumn object names in the parent DataTable of the relation.

childColumnNames
String[]

An array of DataColumn object names in the child DataTable of the relation.

nested
Boolean

A value that indicates whether relationships are nested.

Attributes

Remarks

Any DataRelation object created by using this constructor must be added to the collection with the AddRange method inside of a BeginInit and EndInit block. If this constructor is not called between BeginInit and EndInit a NullReferenceException will occur. In addition, the tables and columns with the specified names must exist at the time the constructor is called.

Applies to

DataRelation(String, String, String, String, String, String[], String[], Boolean)

This constructor is provided for design time support in the Visual Studio environment.

public:
 DataRelation(System::String ^ relationName, System::String ^ parentTableName, System::String ^ parentTableNamespace, System::String ^ childTableName, System::String ^ childTableNamespace, cli::array <System::String ^> ^ parentColumnNames, cli::array <System::String ^> ^ childColumnNames, bool nested);
[System.ComponentModel.Browsable(false)]
public DataRelation (string relationName, string? parentTableName, string? parentTableNamespace, string? childTableName, string? childTableNamespace, string[]? parentColumnNames, string[]? childColumnNames, bool nested);
[System.ComponentModel.Browsable(false)]
public DataRelation (string relationName, string parentTableName, string parentTableNamespace, string childTableName, string childTableNamespace, string[] parentColumnNames, string[] childColumnNames, bool nested);
[<System.ComponentModel.Browsable(false)>]
new System.Data.DataRelation : string * string * string * string * string * string[] * string[] * bool -> System.Data.DataRelation
Public Sub New (relationName As String, parentTableName As String, parentTableNamespace As String, childTableName As String, childTableNamespace As String, parentColumnNames As String(), childColumnNames As String(), nested As Boolean)

Parameters

relationName
String

The name of the DataRelation. If null or an empty string (""), a default name will be given when the created object is added to the DataRelationCollection.

parentTableName
String

The name of the DataTable that is the parent table of the relation.

parentTableNamespace
String

The name of the parent table namespace.

childTableName
String

The name of the DataTable that is the child table of the relation.

childTableNamespace
String

The name of the child table namespace.

parentColumnNames
String[]

An array of DataColumn object names in the parent DataTable of the relation.

childColumnNames
String[]

An array of DataColumn object names in the child DataTable of the relation.

nested
Boolean

A value that indicates whether relationships are nested.

Attributes

Remarks

Any DataRelation object created by using this constructor must then be added to the collection with AddRange. Tables and columns with the specified names must exist at the time the method is called, or if BeginInit has been called before calling this constructor, the tables and columns with the specified names must exist at the time that EndInit is called.

Applies to