Edit

Share via


DataRelationCollection.Add Method

Definition

Overloads

Add(DataRelation)

Adds a DataRelation to the DataRelationCollection.

Add(DataColumn, DataColumn)

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

Add(DataColumn[], DataColumn[])

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

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[])

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)

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)

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)

Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
C#
public void Add(System.Data.DataRelation relation);

Parameters

relation
DataRelation

The DataRelation to add to the collection.

Exceptions

The relation parameter is a null value.

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

The relation has entered an invalid state since it was created.

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Add(DataColumn, DataColumn)

Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs

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

C#
public virtual System.Data.DataRelation Add(System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);

Parameters

parentColumn
DataColumn

The parent column of the relation.

childColumn
DataColumn

The child column of the relation.

Returns

The created relation.

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

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Add(DataColumn[], DataColumn[])

Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs

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

C#
public virtual System.Data.DataRelation Add(System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);

Parameters

parentColumns
DataColumn[]

The parent columns of the relation.

childColumns
DataColumn[]

The child columns of the relation.

Returns

The created relation.

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

The relation has entered an invalid state since it was created.

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

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Add(String, DataColumn, DataColumn)

Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs

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

C#
public virtual System.Data.DataRelation Add(string? name, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);
C#
public virtual System.Data.DataRelation Add(string name, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn);

Parameters

name
String

The name of the relation.

parentColumn
DataColumn

The parent column of the relation.

childColumn
DataColumn

The child column of the relation.

Returns

The created relation.

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

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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

Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs

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

C#
public virtual System.Data.DataRelation Add(string? name, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);
C#
public virtual System.Data.DataRelation Add(string name, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns);

Parameters

name
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

The created DataRelation.

Exceptions

The relation name is a null value.

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

The relation has entered an invalid state since it was created.

Examples

C#
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);
}

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Add(String, DataColumn, DataColumn, Boolean)

Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs

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.

C#
public virtual System.Data.DataRelation Add(string? name, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn, bool createConstraints);
C#
public virtual System.Data.DataRelation Add(string name, System.Data.DataColumn parentColumn, System.Data.DataColumn childColumn, bool createConstraints);

Parameters

name
String

The name of the relation.

parentColumn
DataColumn

The parent column of the relation.

childColumn
DataColumn

The child column of the relation.

createConstraints
Boolean

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

Returns

The created relation.

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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

Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs
Source:
DataRelationCollection.cs

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.

C#
public virtual System.Data.DataRelation Add(string? name, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns, bool createConstraints);
C#
public virtual System.Data.DataRelation Add(string name, System.Data.DataColumn[] parentColumns, System.Data.DataColumn[] childColumns, bool createConstraints);

Parameters

name
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

true to create a constraint; otherwise false.

Returns

The created relation.

Exceptions

The relation name is a null value.

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

The relation has entered an invalid state since it was created.

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

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1