DataTableMappingCollection.Add Method

Definition

Adds a DataTableMapping object to the collection.

Overloads

Add(Object)

Adds an Object that is a table mapping to the collection.

Add(String, String)

Adds a DataTableMapping object to the collection when given a source table name and a DataSet table name.

Add(Object)

Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs

Adds an Object that is a table mapping to the collection.

C#
public int Add(object? value);
C#
public int Add(object value);

Parameters

value
Object

A DataTableMapping object to add to the collection.

Returns

The index of the DataTableMapping object added to the collection.

Implements

Exceptions

The object passed in was not a DataTableMapping object.

Examples

The following example searches for a DataTableMapping within the collection. If the mapping exists in the collection, it is removed. If the mapping does not exist within the collection, it is added to the collection and its index is displayed. The example assumes that a DataTableMappingCollection collection and a DataTableMapping object have been created.

C#
public void ChangedMyMind()
{
    // ...
    // create mappings and mapping
    // ...
    if (mappings.Contains((Object) mapping))
    {
        mappings.Remove((Object) mapping);
    }
    else
    {
        mappings.Add((Object) mapping);
        Console.WriteLine("Index of new mapping: "
            + mappings.IndexOf((Object) mapping));
    }
}

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, String)

Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs

Adds a DataTableMapping object to the collection when given a source table name and a DataSet table name.

C#
public System.Data.Common.DataTableMapping Add(string? sourceTable, string? dataSetTable);
C#
public System.Data.Common.DataTableMapping Add(string sourceTable, string dataSetTable);

Parameters

sourceTable
String

The case-sensitive name of the source table to map from.

dataSetTable
String

The name, which is not case-sensitive, of the DataSet table to map to.

Returns

The DataTableMapping object that was added to the collection.

Examples

The following example creates a DataTableMappingCollection, adds DataTableMapping objects to the collection, and displays a list of the mapped source tables.

C#
public void CreateTableMappings()
{
    DataTableMappingCollection mappings =
        new DataTableMappingCollection();
    mappings.Add("Categories","DataCategories");
    mappings.Add("Orders","DataOrders");
    mappings.Add("Products","DataProducts");
    string message = "TableMappings:\n";
    for(int i=0;i < mappings.Count;i++)
    {
        message += i.ToString() + " "
            + mappings[i].ToString() + "\n";
    }
    Console.WriteLine(message);
}

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