DbConnectionStringBuilder.Item[String] DbConnectionStringBuilder.Item[String] DbConnectionStringBuilder.Item[String] DbConnectionStringBuilder.Item[String] Property


Gets or sets the value associated with the specified key.

 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; }
member this.Item(string) : obj with get, set
Default Public Overridable Property Item(keyword As String) As Object


String String String String

The key of the item to get or set.

Property Value

The value associated with the specified key. If the specified key is not found, trying to get it returns a null reference (Nothing in Visual Basic), and trying to set it creates a new element using the specified key.

Passing a null (Nothing in Visual Basic) key throws an ArgumentNullException. Assigning a null value removes the key/value pair.


keyword is a null reference (Nothing in Visual Basic).

The property is set, and the DbConnectionStringBuilder is read-only.


The property is set, keyword does not exist in the collection, and the DbConnectionStringBuilder has a fixed size.


The following console application creates a new DbConnectionStringBuilder and adds key/value pairs to its connection string, using the Item[String] property.

static void Main()
    DbConnectionStringBuilder builder = new
    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("Press Enter to continue.");
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("Press Enter to continue.")
    End Sub


When you set this property, if the specified key already exists in the dictionary, the value is replaced; otherwise, a new element is created.

Applies to

See also