DataColumnMappingCollection.GetColumnMappingBySchemaAction Method

Definition

Gets a DataColumnMapping for the specified DataColumnMappingCollection, source column name, and MissingMappingAction.

C#
public static System.Data.Common.DataColumnMapping? GetColumnMappingBySchemaAction(System.Data.Common.DataColumnMappingCollection? columnMappings, string sourceColumn, System.Data.MissingMappingAction mappingAction);
C#
public static System.Data.Common.DataColumnMapping GetColumnMappingBySchemaAction(System.Data.Common.DataColumnMappingCollection columnMappings, string sourceColumn, System.Data.MissingMappingAction mappingAction);

Parameters

sourceColumn
String

The case-sensitive source column name to find.

mappingAction
MissingMappingAction

One of the MissingMappingAction values.

Returns

A DataColumnMapping object.

Exceptions

The mappingAction parameter was set to Error, and no mapping was specified.

Examples

The following example searches for a DataColumnMapping with the given source column name within the collection. If the object exists, it is returned. The example assumes that a DataColumnMappingCollection collection and a DataColumnMapping object have been created.

C#
public void FindDataColumnMapping()
{
    // ...
    // create mappings and mapping
    // ...
    if (mappings.Contains("Description"))
        mapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction
            (mappings, "Description", MissingMappingAction.Ignore);
}

Remarks

If the DataColumnMapping exists in the collection, it is returned.

If the DataColumnMapping does not exist in the collection, for a given MissingMappingAction, the following actions occur:

MissingMappingAction Action Taken
Passthrough Creates a DataColumnMapping with the specified source column name as both the source column name and the DataSet column name. This DataColumnMapping is not added to the collection.
Error An InvalidOperationException is generated if the specified column mapping is missing.
Ignore Gets a null value.

Applies to

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

See also