Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DbConnectionStringBuilder.Item Property

Gets or sets the value associated with the specified key.

Namespace:  System.Data.Common
Assembly:  System.Data (in System.Data.dll)
[BrowsableAttribute(false)]
public virtual Object this[
	string keyword
] { get; set; }

Parameters

keyword
Type: System.String

The key of the item to get or set.

Property Value

Type: System.Object
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.
ExceptionCondition
ArgumentNullException

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

NotSupportedException

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

-or-

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

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

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

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();
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.