System.Data.SqlClient Namespace SqlParameterCollection Class
Returns the location of the SqlParameter with the given name within the collection.
[ VB ]
Overloads Public Function IndexOf ( _
ByVal parameterName As String _
) As Integer
[ C# ]
public int IndexOf (
string parameterName
);
[ C++ ]
public: int IndexOf (
String* parameterName
);
[ JScript ]
public function IndexOf (
parameterName : String
) : int;
- parameterName
- The name of the parameter to retrieve.
The location of the SqlParameter within the collection.
IDataParameterCollection.IndexOf
The following example first uses the Contains property to find an SqlParameter with a given ParameterName within the Parameters collection of a specifed SqlCommand object. If the parameter exists, the example uses the IndexOf method to display the index of the parameter; otherwise, the example displays an error.
public void SearchSqlParams ( SqlCommand myCmd ) {
SqlParameterCollection 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 SearchSqlParams ( ByVal myCmd As SqlCommand )
Dim myParams As SqlParameterCollection = 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 |
SqlParameterCollection Members SqlParameterCollection.IndexOf Overload List