DataColumnMappingCollection.Add Method

Definition

Adds a DataColumnMapping object to the collection.

Overloads

Add(Object)

Adds a DataColumnMapping object to the collection.

Add(String, String)

Adds a DataColumnMapping object to the collection when given a source column name and a DataSet column name.

Add(Object)

Source:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs

Adds a DataColumnMapping object to the collection.

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

Parameters

value
Object

A DataColumnMapping object to add to the collection.

Returns

The index of the DataColumnMapping object that was added to the collection.

Implements

Exceptions

The object passed in was not a DataColumnMapping object.

Examples

The following example searches for a DataColumnMapping object 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 DataColumnMappingCollection collection and a DataColumnMapping 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));
    }
}

See also

Applies to

.NET 10 ja muud versioonid
Toode Versioonid
.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:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs

Adds a DataColumnMapping object to the collection when given a source column name and a DataSet column name.

C#
public System.Data.Common.DataColumnMapping Add(string? sourceColumn, string? dataSetColumn);
C#
public System.Data.Common.DataColumnMapping Add(string sourceColumn, string dataSetColumn);

Parameters

sourceColumn
String

The case-sensitive name of the source column to map to.

dataSetColumn
String

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

Returns

The DataColumnMapping object that was added to the collection.

Examples

The following example creates a DataColumnMappingCollection collection, adds DataColumnMapping objects to the collection, and displays a list of the mapped source columns.

C#
public void CreateColumnMappings()
{
    DataColumnMappingCollection mappings =
        new DataColumnMappingCollection();
    mappings.Add("Category Name","DataCategory");
    mappings.Add("Description","DataDescription");
    mappings.Add("Picture","DataPicture");
    string myMessage = "ColumnMappings:\n";
    for(int i=0;i < mappings.Count;i++)
    {
        myMessage += i.ToString() + " "
            + mappings[i].ToString() + "\n";
    }
    Console.WriteLine(myMessage);
}

See also

Applies to

.NET 10 ja muud versioonid
Toode Versioonid
.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