次の方法で共有


SqlParameterCollection.IndexOf メソッド (Object)

SqlParameter の、コレクション内での位置を取得します。

Overloads Public Overridable Function IndexOf( _
   ByVal value As Object _) As Integer Implements IList.IndexOf
[C#]
public virtual int IndexOf(objectvalue);
[C++]
public: virtual int IndexOf(Object* value);
[JScript]
public function IndexOf(
   value : Object) : int;

パラメータ

戻り値

SqlParameter の、コレクション内での 0 から始まる位置。

実装

IList.IndexOf

使用例

[Visual Basic, C#, C++] SqlParameterCollection コレクション内で SqlParameter オブジェクトを検索する例を次に示します。目的のパラメータが存在する場合は、そのパラメータの名前とインデックスを表示します。目的のパラメータが存在しない場合は、エラーを表示します。この例では、 SqlParameterCollection コレクションが SqlCommand によって既に作成されていることを前提にしています。

 
Public Sub SearchSqlParams()
    ' ...
    ' create SqlCommand myCmd and SqlParameter myParameter
    ' ...
    If Not myCmd.Parameters.Contains(myParameter) Then
        MessageBox.Show("ERROR: no such parameter in the collection")
    Else
        MessageBox.Show(("match on parameter #" & myCmd.Parameters.IndexOf(myParameter).ToString()))
    End If
End Sub 'SearchSqlParams

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

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

[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.IndexOf オーバーロードの一覧