แก้ไข

แชร์ผ่าน


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.

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

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

Applies to

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.

public:
 System::Data::Common::DataTableMapping ^ Add(System::String ^ sourceTable, System::String ^ dataSetTable);
public System.Data.Common.DataTableMapping Add (string? sourceTable, string? dataSetTable);
public System.Data.Common.DataTableMapping Add (string sourceTable, string dataSetTable);
member this.Add : string * string -> System.Data.Common.DataTableMapping
Public Function Add (sourceTable As String, dataSetTable As String) As DataTableMapping

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.

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);
}
Public Sub CreateTableMappings()
    Dim mappings As New DataTableMappingCollection()
    mappings.Add("Categories", "DataCategories")
    mappings.Add("Orders", "DataOrders")
    mappings.Add("Products", "DataProducts")
    Dim message As String = "TableMappings:" & ControlChars.Cr
    Dim i As Integer
    For i = 0 To mappings.Count - 1
        message &= i.ToString() & " " + mappings(i).ToString() _
           & ControlChars.Cr
    Next i
    Console.WriteLine(message)
End Sub

Applies to