DbConnectionStringBuilder.Item[String] プロパティ

定義

指定したキーに関連付けられている値を取得または設定します。

public:
 virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ keyword); void set(System::String ^ keyword, System::Object ^ value); };
public virtual object this[string keyword] { get; set; }
[System.ComponentModel.Browsable(false)]
public virtual object this[string keyword] { get; set; }
member this.Item(string) : obj with get, set
[<System.ComponentModel.Browsable(false)>]
member this.Item(string) : obj with get, set
Default Public Overridable Property Item(keyword As String) As Object

パラメーター

keyword
String

取得または設定する項目のキー。

プロパティ値

指定したキーに関連付けられている値。 指定したキーが見つからない場合、取得しようとすると ArgumentExceptionがスローされ、設定しようとすると、指定したキーを使用して新しい要素が作成されます。

null (Visual Basic で Nothing) キーを渡すと、ArgumentNullException がスローされます。 null 値を割り当てると、キーと値のペアが削除されます。

属性

例外

keywordの値がコレクションに設定されていません。

keyword は null 参照です (Visual Basic では Nothing)。

プロパティが設定され、 DbConnectionStringBuilder は読み取り専用です。

-又は-

プロパティが設定され、 keyword がコレクションに存在せず、 DbConnectionStringBuilder のサイズが固定されています。

次のコンソール アプリケーションは、DbConnectionStringBuilder プロパティを使用して、新しい Item[] を作成し、その接続文字列にキーと値のペアを追加します。

static void Main()
{
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder["Data Source"] = "(local)";

    // Note that Item is the indexer, so
    // you do not include it in the reference.
    builder["integrated security"] = true;
    builder["Initial Catalog"] = "AdventureWorks";

    // Overwrite the existing value for the Data Source key,
    // because it already exists within the collection.
    builder["Data Source"] = ".";

    Console.WriteLine(builder.ConnectionString);
    Console.WriteLine();
    Console.WriteLine("Press Enter to continue.");
    Console.ReadLine();
}
Module Module1

    Sub Main()
        Dim builder As New DbConnectionStringBuilder
        builder.Item("Data Source") = "(local)"

        ' Item is the default property, so 
        ' you need not include it in the reference.
        builder("integrated security") = True
        builder.Item("Initial Catalog") = "AdventureWorks"

        ' Overwrite the existing value for the data source value, 
        ' because it already exists within the collection.
        builder.Item("Data Source") = "."

        Console.WriteLine(builder.ConnectionString)
        Console.WriteLine()
        Console.WriteLine("Press Enter to continue.")
        Console.ReadLine()
    End Sub

注釈

このプロパティを設定すると、指定したキーがディクショナリに既に存在する場合は、値が置き換えられます。それ以外の場合は、新しい要素が作成されます。

適用対象

こちらもご覧ください