ערוך

שתף באמצעות


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.

public:
 virtual int Add(System::Object ^ value);
public int Add (object? value);
public int Add (object value);
abstract member Add : obj -> int
override this.Add : obj -> int
Public Function Add (value As Object) As Integer

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.

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));
    }
}
Public Sub ChangedMyMind()
    ' ...
    ' create mappings and mapping
    ' ...
    If mappings.Contains(CType(mapping, Object)) Then
        mappings.Remove(CType(mapping, Object))
    Else
        mappings.Add(CType(mapping, Object))
        Console.WriteLine("Index of new mapping: " + _
           mappings.IndexOf(CType(mapping, Object)).ToString())
    End If
End Sub

See also

Applies to

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.

public:
 System::Data::Common::DataColumnMapping ^ Add(System::String ^ sourceColumn, System::String ^ dataSetColumn);
public System.Data.Common.DataColumnMapping Add (string? sourceColumn, string? dataSetColumn);
public System.Data.Common.DataColumnMapping Add (string sourceColumn, string dataSetColumn);
member this.Add : string * string -> System.Data.Common.DataColumnMapping
Public Function Add (sourceColumn As String, dataSetColumn As String) As DataColumnMapping

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.

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);
}
Public Sub CreateColumnMappings()
    Dim mappings As New DataColumnMappingCollection()
    mappings.Add("Category Name", "DataCategory")
    mappings.Add("Description", "DataDescription")
    mappings.Add("Picture", "DataPicture")
    Dim myMessage As String = "ColumnMappings:" + ControlChars.Cr
    Dim i As Integer
    For i = 0 To mappings.Count - 1
        myMessage += i.ToString() + " " + mappings(i).ToString() _
           + ControlChars.Cr
    Next i
    Console.WriteLine(myMessage)
End Sub

See also

Applies to