This documentation is archived and is not being maintained.

SqlParameterCollection.Contains Method

Gets a value indicating whether a SqlParameter exists in the collection.

Overload List

Gets a value indicating whether a SqlParameter exists in the collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function Contains(Object) As Boolean Implements IList.Contains
[C#] public virtual bool Contains(object);
[C++] public: virtual bool Contains(Object*);
[JScript] public function Contains(Object) : Boolean;

Gets a value indicating whether a SqlParameter with the specified parameter name exists in the collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function Contains(String) As Boolean Implements IDataParameterCollection.Contains
[C#] public virtual bool Contains(string);
[C++] public: virtual bool Contains(String*);
[JScript] public function Contains(String) : Boolean;

Example

[Visual Basic, C#, C++] The following example looks for a SqlParameter with a given ParameterName within a SqlParameterCollection. If the parameter exists, the example displays the index of the parameter. If the parameter does not exist, the example displays an error. This example assumes that a SqlParameterCollection has already been created by a SqlCommand.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Contains. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub SearchSqlParams()
    ' ...
    ' create SqlCommand myCmd
    ' ...
    If Not myCmd.Parameters.Contains("Description") Then
        MessageBox.Show("ERROR: no such parameter in the collection")
    Else
        MessageBox.Show(("match on parameter #" & myCmd.Parameters.IndexOf("Description").ToString()))
    End If
End Sub 'SearchSqlParams

[C#] 
public void SearchSqlParams() {
    // ...
    // create SqlCommand myCmd
    // ...
    if (!myCmd.Parameters.Contains("Description"))
       MessageBox.Show("ERROR: no such parameter in the collection");
    else
       MessageBox.Show("match on parameter #" +
                 myCmd.Parameters.IndexOf("Description").ToString());
 }

[C++] 
public:
void SearchSqlParams() {
    // ...
    // create SqlCommand myCmd
    // ...
    if (!myCmd->Parameters->Contains(S"Description"))
       MessageBox::Show(S"ERROR: no such parameter in the collection");
    else
       MessageBox::Show(String::Format( S"match on parameter #{0}", __box(myCmd->Parameters->IndexOf(S"Description"))));
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

SqlParameterCollection Class | SqlParameterCollection Members | System.Data.SqlClient Namespace

Show: