次の方法で共有


SqlParameterCollection.Item プロパティ (String)

指定した名前の SqlParameter を取得します。

[C#] C# では、このプロパティは SqlParameterCollection クラスのインデクサになります。

Overloads Public Default Property Item( _
   ByVal parameterName As String _) As SqlParameter
[C#]
public SqlParameter this[stringparameterName] {get; set;}
[C++]
public: __property SqlParameter* get_Item(String* parameterName);public: __property void set_Item(String* parameterName,   SqlParameter*);
[JScript]
returnValue = SqlParameterCollectionObject.Item(parameterName);SqlParameterCollectionObject.Item(parameterName) = returnValue;またはreturnValue = SqlParameterCollectionObject(parameterName);SqlParameterCollectionObject(parameterName) = returnValue;

[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。

引数 [JScript]

  • parameterName
    取得するパラメータの名前。

パラメータ [Visual Basic, C#, C++]

  • parameterName
    取得するパラメータの名前。

プロパティ値

指定した名前の SqlParameter 。パラメータが見つからない場合は null 参照 (Visual Basic では Nothing) 。

例外

例外の種類 条件
IndexOutOfRangeException 指定したファイルが存在しません。

使用例

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

 
Public Sub SearchSqlParams()
    ' ...
    ' create SqlCommand myCmd
    ' ...
    Dim mySearch As SqlParameter = CType(myCmd.Parameters("Description"), SqlParameter)
    If mySearch Is Nothing 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
    // ...
    SqlParameter mySearch = (SqlParameter) myCmd.Parameters["Description"];
    if (mySearch == null)
       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
    // ...
    SqlParameter* mySearch = dynamic_cast<SqlParameter*> (myCmd->Parameters->Item[S"Description"]);
    if (mySearch == 0)
       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 ファミリ

参照

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