Bewerken

Share via


IColumnMappingCollection.IndexOf(String) Method

Definition

Gets the location of the DataColumnMapping object with the specified source column name. The name is case-sensitive.

public:
 int IndexOf(System::String ^ sourceColumnName);
public int IndexOf (string? sourceColumnName);
public int IndexOf (string sourceColumnName);
abstract member IndexOf : string -> int
Public Function IndexOf (sourceColumnName As String) As Integer

Parameters

sourceColumnName
String

The case-sensitive name of the source column.

Returns

The zero-based location of the DataColumnMapping object with the specified source column name.

Examples

The following example searches for an instance of the derived class, DataColumnMapping, with the given source column name within a DataColumnMappingCollection collection. If the DataColumnMapping exists, the example displays the name and the index of the mapping. If the mapping does not exist, the example displays an error. This example assumes that a DataColumnMappingCollection collection has been created.

public void FindDataColumnMapping()
{
    // ...
    // create columnMappings
    // ...
    if (!columnMappings.Contains("Description"))
    {
        Console.WriteLine("Error: no such table in collection.");
    }
    else
    {
        Console.WriteLine("Name {0}",
            columnMappings["Description"].ToString());
        Console.WriteLine("Index: {0}",
            columnMappings.IndexOf("Description").ToString());
    }
}
Public Sub FindDataColumnMapping()
    ' ...
    ' create columnMappings
    ' ...
    If Not columnMappings.Contains("Description") Then
        Console.WriteLine("Error: no such table in collection.")
    Else
       Console.WriteLine("Name: {0}", _
           columnMappings("Description").ToString())
       Console.WriteLine("Index: {0}", _
           columnMappings.IndexOf("Description").ToString())
    End If
End Sub

Applies to