Export (0) Print
Expand All

DbConnectionStringBuilder.Keys Property

Gets an ICollection that contains the keys in the DbConnectionStringBuilder.

Namespace:  System.Data.Common
Assembly:  System.Data (in System.Data.dll)

'Declaration
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property Keys As ICollection

Property Value

Type: System.Collections.ICollection
An ICollection that contains the keys in the DbConnectionStringBuilder.

Implements

IDictionary.Keys

The order of the values in the ICollection is unspecified, but it is the same order as the associated values in the ICollection returned by the Values property.

The returned ICollection is not a static copy; instead, the ICollection refers back to the keys in the original DbConnectionStringBuilder. Therefore, changes to the DbConnectionStringBuilder are reflected in the ICollection.

The following console application example creates a new DbConnectionStringBuilder, and adds some keys. The code loops through the ICollection returned by the Keys property displaying the key/value pairs, and then adds a new key. Because the Keys property returns a dynamic ICollection, the second loop displays all the key/value pairs, including the newest item.

Sub Main()
    Dim builder As New DbConnectionStringBuilder
    builder("Data Source") = "(local)"
    builder("integrated security") = True
    builder("Initial Catalog") = "AdventureWorks;NewValue=Bad" 

    ' Obtain reference to the collection of keys. 
    Dim keys As ICollection = builder.Keys

    Console.WriteLine("Keys before adding TimeOut:")
    For Each key As String In keys
        Console.WriteLine("{0}={1}", key, builder(key))
    Next 

    ' Add a new item to the collection.
    builder("Timeout") = 300

    Console.WriteLine()
    Console.WriteLine("Keys after adding TimeOut:")

    ' Because the Keys property is dynamically updated,  
    ' the following loop includes the Timeout key. 
    For Each key As String In keys
        Console.WriteLine("{0}={1}", key, builder(key))
    Next

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Show:
© 2014 Microsoft