System.Data.Common Namespace DataColumnMappingCollection Class
Returns the index of a DataColumnMapping with the specified SourceColumn name.
[ VB ]
NotOverridable Overloads Public Function IndexOf ( _
ByVal sourceColumn As String _
) As Integer Implements IColumnMappingCollection.IndexOf
[ C# ]
public int IndexOf (
String sourceColumn
);
[ C++ ]
public: __sealed int IndexOf (
String* sourceColumn
);
[ JScript ]
public function IndexOf (
sourceColumn : String
) : int
- sourceColumn
- The case-sensitive name of a SourceColumn.
IColumnMappingCollection.IndexOf
The index of the DataColumnMapping if it is in the collection; otherwise, -1.
Use the IndexOf method to determine the index of a given column mapping object.
Before calling IndexOf, you can test for the existence of a column mapping by using the Contains method.
The following example searches for a DataColumnMapping object with the given source column name within a DataColumnMappingCollection. If the DataColumnMapping exists, the code displays the name and index of the mapping; otherwise, it displays an error.
public void FindDataColumnMapping ( DataTableMapping myTableMap ) {
// get column mappings
DataColumnMappingCollection myFieldsMaps = myTableMap.ColumnMappings;
if ( myFieldsMaps.Contains ( "Description" ) ) {
MessageBox.Show ( "Name: " + myFieldsMaps [ "Description" ].ToString ( )
+ "\nIndex: " + myFieldsMaps.IndexOf ( "Description" ).ToString ( ) );
} else {
MessageBox.Show ( "Error: no such field in collection" );
}
}
Public Sub FindDataColumnMapping ( ByVal myTableMap As DataTableMapping )
' get column mappings
Dim myFieldsMaps As DataColumnMappingCollection = myTableMap.ColumnMappings;
If myFieldsMaps.Contains ( "Description" ) Then
MessageBox.Show ( "Name: " + myFieldsMaps ( "Description" ).ToString ( ) _
+ ControlChars.Cr + "Index: " + myFieldsMaps.IndexOf ( "Description" ).ToString ( ) )
Else
MessageBox.Show ( "Error: no such field in collection" )
End If
End Sub |
|
C# |
VB |
DataColumnMappingCollection Members DataColumnMappingCollection.IndexOf Overload List Contains