asp.net.ph

SqlParameterCollection.Item Property ( String )

System.Data.SqlClient Namespace   SqlParameterCollection Class


Returns the SqlParameter with the specified name.

Syntax


SqlParameter variable = SqlParameterCollection.Item [ parameterName ];
... or ...
SqlParameter variable = SqlParameterCollection [ parameterName ];
  C# VB JScript

Parameters

parameterName
The name of the parameter to retrieve.

Property Value

The SqlParameter with the specified name, or a null reference if the parameter is not found.

Implements

IDataParameterCollection.Item

Exceptions


Exception Type Condition
IndexOutOfRangeException Occurs when the specified name does not exist.

Example

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" );

}
  C# VB

See Also

SqlParameterCollection Members   SqlParameterCollection.Item Overload List Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph