System.Data.OleDb Namespace OleDbParameterCollection Class
Returns the location of a parameter within the collection.
1. Returns the location of a given OleDbParameter within the collection.
2. Returns the location of the OleDbParameter with the given name within the collection.
The following example first uses the Contains property to find an OleDbParameter with a given ParameterName within the Parameters collection of a specifed OleDbCommand object. If the parameter exists, the example uses the IndexOf method to display the index of the parameter; otherwise, the example displays an error.
NOTE: This example uses one of the overloaded versions of the IndexOf method. For other examples that may be available, see the individual overload topics.
public void SearchOleDbParams ( OleDbCommand myCmd ) {
OleDbParameterCollection myParams = myCmd.Parameters;
if ( myParams.Contains ( "Model" ) )
MessageBox.Show ( "Name: " + myParams [ "Model" ].ToString ( ) +
"Index: " + myParams.IndexOf ( "Model" ).ToString ( ) );
else
MessageBox.Show ( "Sorry, no such parameter found in the collection" );
}
Public Sub SearchOleDbParams ( ByVal myCmd As OleDbCommand )
Dim myParams As OleDbParameterCollection = myCmd.Parameters
If myParams.Contains ( "Model" ) Then
MessageBox.Show ( "Name: " & myParams ( "Model" ).ToString ( ) & _
"Index: " & myParams.IndexOf ( "Model" ).ToString ( ) )
Else
MessageBox.Show ( "Sorry, no such parameter found in the collection" )
End If
End Sub |
|
C# |
VB |
OleDbParameterCollection Members