DataRelationCollection.Add DataRelationCollection.Add DataRelationCollection.Add DataRelationCollection.Add Method

Definition

Overloads

Add(DataRelation) Add(DataRelation) Add(DataRelation) Add(DataRelation)

Adds a DataRelation to the DataRelationCollection.

Add(DataColumn, DataColumn) Add(DataColumn, DataColumn) Add(DataColumn, DataColumn) Add(DataColumn, DataColumn)

Creates a DataRelation with a specified parent and child column, and adds it to the collection.

Add(DataColumn[], DataColumn[]) Add(DataColumn[], DataColumn[]) Add(DataColumn[], DataColumn[]) Add(DataColumn[], DataColumn[])

Creates a DataRelation with the specified parent and child columns, and adds it to the collection.

Add(String, DataColumn, DataColumn) Add(String, DataColumn, DataColumn) Add(String, DataColumn, DataColumn) Add(String, DataColumn, DataColumn)

Creates a DataRelation with the specified name, and parent and child columns, and adds it to the collection.

Add(String, DataColumn[], DataColumn[]) Add(String, DataColumn[], DataColumn[]) Add(String, DataColumn[], DataColumn[]) Add(String, DataColumn[], DataColumn[])

Creates a DataRelation with the specified name and arrays of parent and child columns, and adds it to the collection.

Add(String, DataColumn, DataColumn, Boolean) Add(String, DataColumn, DataColumn, Boolean) Add(String, DataColumn, DataColumn, Boolean) Add(String, DataColumn, DataColumn, Boolean)

Creates a DataRelation with the specified name, parent and child columns, with optional constraints according to the value of the createConstraints parameter, and adds it to the collection.

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

Creates a DataRelation with the specified name, arrays of parent and child columns, and value specifying whether to create a constraint, and adds it to the collection.

Add(DataRelation) Add(DataRelation) Add(DataRelation) Add(DataRelation)

Adds a DataRelation to the DataRelationCollection.

public:
 void Add(System::Data::DataRelation ^ relation);
public void Add (System.Data.DataRelation relation);
member this.Add : System.Data.DataRelation -> unit
Public Sub Add (relation As DataRelation)

Parameters

relation
DataRelation DataRelation DataRelation DataRelation

The DataRelation to add to the collection.

Exceptions

The relation already belongs to this collection, or it belongs to another collection.

The collection already has a relation with the specified name. (The comparison is not case sensitive.)

Remarks

If the relation is successfully added to the collection, the CollectionChanged event occurs.

When a DataRelation object is added to the collection, ForeignKeyConstraint and UniqueConstraint objects are created by default if they do not already exist.

See also

Add(DataColumn, DataColumn) Add(DataColumn, DataColumn) Add(DataColumn, DataColumn) Add(DataColumn, DataColumn)

Creates a DataRelation with a specified parent and child column, and adds it to the collection.

public:
 virtual System::Data::DataRelation ^ Add(System::Data::DataColumn ^ parentColumn, System::Data::DataColumn ^ childColumn);
public virtual System.Data.DataRelation Add (System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);
abstract member Add : System.Data.DataColumn * System.Data.DataColumn -> System.Data.DataRelation
override this.Add : System.Data.DataColumn * System.Data.DataColumn -> System.Data.DataRelation
Public Overridable Function Add (parentColumn As DataColumn, childColumn As DataColumn) As DataRelation

Parameters

parentColumn
DataColumn DataColumn DataColumn DataColumn

The parent column of the relation.

childColumn
DataColumn DataColumn DataColumn DataColumn

The child column of the relation.

Returns

Remarks

When a DataRelation object is added to the collection, ForeignKeyConstraint and UniqueConstraint objects are created by default if they do not already exist.

See also

Add(DataColumn[], DataColumn[]) Add(DataColumn[], DataColumn[]) Add(DataColumn[], DataColumn[]) Add(DataColumn[], DataColumn[])

Creates a DataRelation with the specified parent and child columns, and adds it to the collection.

public:
 virtual System::Data::DataRelation ^ Add(cli::array <System::Data::DataColumn ^> ^ parentColumns, cli::array <System::Data::DataColumn ^> ^ childColumns);
public virtual System.Data.DataRelation Add (System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);
abstract member Add : System.Data.DataColumn[] * System.Data.DataColumn[] -> System.Data.DataRelation
override this.Add : System.Data.DataColumn[] * System.Data.DataColumn[] -> System.Data.DataRelation
Public Overridable Function Add (parentColumns As DataColumn(), childColumns As DataColumn()) As DataRelation

Parameters

parentColumns
DataColumn[]

The parent columns of the relation.

childColumns
DataColumn[]

The child columns of the relation.

Returns

Exceptions

The relation already belongs to this collection, or it belongs to another collection.

The collection already has a relation with the same name. (The comparison is not case sensitive.)

Remarks

When a DataRelation object is added to the collection, ForeignKeyConstraint and UniqueConstraint objects are created by default if they do not already exist.

See also

Add(String, DataColumn, DataColumn) Add(String, DataColumn, DataColumn) Add(String, DataColumn, DataColumn) Add(String, DataColumn, DataColumn)

Creates a DataRelation with the specified name, and parent and child columns, and adds it to the collection.

public:
 virtual System::Data::DataRelation ^ Add(System::String ^ name, System::Data::DataColumn ^ parentColumn, System::Data::DataColumn ^ childColumn);
public virtual System.Data.DataRelation Add (string name, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);
abstract member Add : string * System.Data.DataColumn * System.Data.DataColumn -> System.Data.DataRelation
override this.Add : string * System.Data.DataColumn * System.Data.DataColumn -> System.Data.DataRelation
Public Overridable Function Add (name As String, parentColumn As DataColumn, childColumn As DataColumn) As DataRelation

Parameters

name
String String String String

The name of the relation.

parentColumn
DataColumn DataColumn DataColumn DataColumn

The parent column of the relation.

childColumn
DataColumn DataColumn DataColumn DataColumn

The child column of the relation.

Returns

Remarks

When a DataRelation object is added to the collection, ForeignKeyConstraint and UniqueConstraint objects are created by default if they do not already exist.

See also

Add(String, DataColumn[], DataColumn[]) Add(String, DataColumn[], DataColumn[]) Add(String, DataColumn[], DataColumn[]) Add(String, DataColumn[], DataColumn[])

Creates a DataRelation with the specified name and arrays of parent and child columns, and adds it to the collection.

public:
 virtual System::Data::DataRelation ^ Add(System::String ^ name, cli::array <System::Data::DataColumn ^> ^ parentColumns, cli::array <System::Data::DataColumn ^> ^ childColumns);
public virtual System.Data.DataRelation Add (string name, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);
abstract member Add : string * System.Data.DataColumn[] * System.Data.DataColumn[] -> System.Data.DataRelation
override this.Add : string * System.Data.DataColumn[] * System.Data.DataColumn[] -> System.Data.DataRelation
Public Overridable Function Add (name As String, parentColumns As DataColumn(), childColumns As DataColumn()) As DataRelation

Parameters

name
String String String String

The name of the DataRelation to create.

parentColumns
DataColumn[]

An array of parent DataColumn objects.

childColumns
DataColumn[]

An array of child DataColumn objects.

Returns

Exceptions

The relation already belongs to this collection, or it belongs to another collection.

The collection already has a relation with the same name. (The comparison is not case sensitive.)

Examples

private void AddRelation() 
{
    DataTable table = new DataTable();
    DataColumn column1 = table.Columns.Add("Column1");
    DataColumn column2 = table.Columns.Add("Column2");
    table.ChildRelations.Add("New Relation", column1, column2);
}
Private Sub AddRelation()
    Dim table As New DataTable()
    Dim column1 As DataColumn = table.Columns.Add("Column1")
    Dim column2 As DataColumn = table.Columns.Add("Column2")
    table.ChildRelations.Add("New Relation", column1, column2)
End Sub

Remarks

If the relation is successfully added to the collection, the CollectionChanged event occurs.

When a DataRelation object is added to the collection, ForeignKeyConstraint and UniqueConstraint objects are created by default if they do not already exist.

See also

Add(String, DataColumn, DataColumn, Boolean) Add(String, DataColumn, DataColumn, Boolean) Add(String, DataColumn, DataColumn, Boolean) Add(String, DataColumn, DataColumn, Boolean)

Creates a DataRelation with the specified name, parent and child columns, with optional constraints according to the value of the createConstraints parameter, and adds it to the collection.

public:
 virtual System::Data::DataRelation ^ Add(System::String ^ name, System::Data::DataColumn ^ parentColumn, System::Data::DataColumn ^ childColumn, bool createConstraints);
public virtual System.Data.DataRelation Add (string name, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn, bool createConstraints);
abstract member Add : string * System.Data.DataColumn * System.Data.DataColumn * bool -> System.Data.DataRelation
override this.Add : string * System.Data.DataColumn * System.Data.DataColumn * bool -> System.Data.DataRelation
Public Overridable Function Add (name As String, parentColumn As DataColumn, childColumn As DataColumn, createConstraints As Boolean) As DataRelation

Parameters

name
String String String String

The name of the relation.

parentColumn
DataColumn DataColumn DataColumn DataColumn

The parent column of the relation.

childColumn
DataColumn DataColumn DataColumn DataColumn

The child column of the relation.

createConstraints
Boolean Boolean Boolean Boolean

true to create constraints; otherwise false. (The default is true).

Returns

Remarks

When a DataRelation object is added to the collection, ForeignKeyConstraint and UniqueConstraint objects are created by default if they do not already exist. To prevent this, you can set createConstraints to false.

See also

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

Creates a DataRelation with the specified name, arrays of parent and child columns, and value specifying whether to create a constraint, and adds it to the collection.

public:
 virtual System::Data::DataRelation ^ Add(System::String ^ name, cli::array <System::Data::DataColumn ^> ^ parentColumns, cli::array <System::Data::DataColumn ^> ^ childColumns, bool createConstraints);
public virtual System.Data.DataRelation Add (string name, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns, bool createConstraints);
abstract member Add : string * System.Data.DataColumn[] * System.Data.DataColumn[] * bool -> System.Data.DataRelation
override this.Add : string * System.Data.DataColumn[] * System.Data.DataColumn[] * bool -> System.Data.DataRelation
Public Overridable Function Add (name As String, parentColumns As DataColumn(), childColumns As DataColumn(), createConstraints As Boolean) As DataRelation

Parameters

name
String String String String

The name of the DataRelation to create.

parentColumns
DataColumn[]

An array of parent DataColumn objects.

childColumns
DataColumn[]

An array of child DataColumn objects.

createConstraints
Boolean Boolean Boolean Boolean

true to create a constraint; otherwise false.

Returns

Exceptions

The relation already belongs to this collection, or it belongs to another collection.

The collection already has a relation with the same name. (The comparison is not case sensitive.)

Remarks

When a DataRelation object is added to the collection, ForeignKeyConstraint and UniqueConstraint objects are created by default if they do not already exist.

See also

Applies to