System.Data.SqlClient Namespace SqlParameterCollection Class
Returns the SqlParameter with the specified name.
SqlParameter variable = SqlParameterCollection.Item [ parameterName ];
... or ...
SqlParameter variable = SqlParameterCollection [ parameterName ];
dim variable as SqlParameter = SqlParameterCollection.Item ( parameterName )
... or ...
dim variable as SqlParameter = SqlParameterCollection ( parameterName )
variable : SqlParameter = SqlParameterCollection.Item ( parameterName );
... or ...
variable : SqlParameter = SqlParameterCollection ( parameterName ); |
|
C# |
VB |
JScript |
- parameterName
- The name of the parameter to retrieve.
The SqlParameter with the specified name, or a null reference if the parameter is not found.
IDataParameterCollection.Item
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 displays the index of the parameter; otherwise, the example displays an error.
NOTE: This example uses one of the overloaded versions of the Item property ( SqlParameterCollection indexer ). For other examples that may be available, see the individual overload topics.
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.Item Overload List