This documentation is archived and is not being maintained.

DataColumnMapping.GetDataColumnBySchemaAction Method

Gets a DataColumn from the given DataTable using the MissingSchemaAction and the DataSetColumn property.

[Visual Basic]
Public Function GetDataColumnBySchemaAction( _
   ByVal dataTable As DataTable, _
   ByVal dataType As Type, _
   ByVal schemaAction As MissingSchemaAction _
) As DataColumn
[C#]
public DataColumn GetDataColumnBySchemaAction(
 DataTable dataTable,
 Type dataType,
 MissingSchemaAction schemaAction
);
[C++]
public: DataColumn* GetDataColumnBySchemaAction(
 DataTable* dataTable,
 Type* dataType,
 MissingSchemaAction schemaAction
);
[JScript]
public function GetDataColumnBySchemaAction(
   dataTable : DataTable,
 dataType : Type,
 schemaAction : MissingSchemaAction
) : DataColumn;

Parameters

dataTable
The DataTable to get the column from.
dataType
The Type of the data column.
schemaAction
One of the MissingSchemaAction values.

Return Value

A DataColumn.

Remarks

If the given dataType is not convertible to the Type of the DataColumn, an exception is generated.

If the DataColumn does not exist in the DataTable, for a given MissingSchemaAction, the following actions occur:

MissingSchemaAction Action Taken
Error An exception is generated.
Ignore Gets a null value.
Add A DataColumn is created of type dataType with the name from the DataSetColumn property, but it is not added to the dataTable.

Example

[Visual Basic, C#, C++] The following example gets the DataColumn that is a Single for a given DataTable. If no column of type Single exists in DataTable, a null reference (Nothing in Visual Basic) is returned. This example assumes a DataTable and a DataColumnMapping have been created.

[Visual Basic] 
Public Sub CreateDataColumn()
    ' ...
    ' create myDataTable and myNewMapping
    ' ...
    Dim myCurrentColumn As DataColumn = _
       myNewMapping.GetDataColumnBySchemaAction _
       (myDataTable, GetType(Single), MissingSchemaAction.Ignore)
End Sub

[C#] 
public void CreateDataColumn() {
   // ...
   // create myDataTable and myNewMapping
   // ...
   DataColumn myCurrentColumn =
       myNewMapping.GetDataColumnBySchemaAction 
       (myDataTable, typeof(Single), MissingSchemaAction.Ignore);
}

[C++] 
void CreateDataColumn() {
   // ...
   // create myDataTable and myNewMapping
   // ...
   DataColumn* myCurrentColumn =
       myNewMapping->GetDataColumnBySchemaAction 
       (myDataTable, __typeof(Single), MissingSchemaAction::Ignore);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumnMapping Class | DataColumnMapping Members | System.Data.Common Namespace

Show: