Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AppendKeyValuePair Method (StringBuilder, String, String)

DbConnectionStringBuilder.AppendKeyValuePair Method (StringBuilder, String, String)

Provides an efficient and safe way to append a key and value to an existing StringBuilder object.

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

'Declaration
Public Shared Sub AppendKeyValuePair ( _
	builder As StringBuilder, _
	keyword As String, _
	value As String _
)

Parameters

builder
Type: System.Text.StringBuilder

The StringBuilder to which to add the key/value pair.

keyword
Type: System.String

The key to be added.

value
Type: System.String

The value for the supplied key.

This method allows developers using a StringBuilder to create a collection of key/value pairs to be able to take advantage of the features included in the DbConnectionStringBuilder class when you add key/value pairs, without having to incur the overhead of creating and maintaining a DbConnectionStringBuilder instance. The AppendKeyValuePair method formats the key and value correctly and adds the new string to the supplied StringBuilder.

If some process has created a connection string, but now an application must perform a simple modification to that connection string, it may be more efficient to just add the key/value pair using a StringBuilder object. Instead of creating a new DbConnectionStringBuilder, developers can call the AppendKeyValuePair method, passing in a StringBuilder that contains the supplied connection string. The following procedure shows a simple example of this technique.

Public Function AddPooling(ByVal connectionString As String) As String 
    Dim builder As New StringBuilder(connectionString)
    DbConnectionStringBuilder.AppendKeyValuePair(builder, "Pooling", "True")
    Return builder.ToString()
End Function

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft