次の方法で共有


SqlParameterCollection.Contains メソッド (String)

指定したパラメータ名の SqlParameter がコレクション内に存在するかどうかを示す値を取得します。

Overloads Public Overridable Function Contains( _
   ByVal value As String _) As Boolean Implements IDataParameterCollection.Contains
[C#]
public virtual bool Contains(stringvalue);
[C++]
public: virtual bool Contains(String* value);
[JScript]
public function Contains(
   value : String) : Boolean;

パラメータ

  • value
    検索する SqlParameter オブジェクトの名前。

戻り値

コレクションに目的のパラメータが含まれている場合は true 。それ以外の場合は false

実装

IDataParameterCollection.Contains

使用例

[Visual Basic, C#, C++] SqlParameterCollection 内で、指定した ParameterNameSqlParameter を検索する例を次に示します。目的のパラメータが存在する場合は、そのパラメータの名前とインデックスを表示します。目的のパラメータが存在しない場合は、エラーを表示します。この例では、 SqlParameterCollectionSqlCommand によって既に作成されていることを前提にしています。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

SqlParameterCollection クラス | SqlParameterCollection メンバ | System.Data.SqlClient 名前空間 | SqlParameterCollection.Contains オーバーロードの一覧