Редагувати

Поділитися через


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

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

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.

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

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

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.

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

The created relation.

Exceptions

The relation argument 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

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.

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

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

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.

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

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

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

Applies to

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.

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

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

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.

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

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