DbConnectionStringBuilder.AppendKeyValuePair DbConnectionStringBuilder.AppendKeyValuePair DbConnectionStringBuilder.AppendKeyValuePair DbConnectionStringBuilder.AppendKeyValuePair Method

Definition

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

Overloads

AppendKeyValuePair(StringBuilder, String, String) AppendKeyValuePair(StringBuilder, String, String) AppendKeyValuePair(StringBuilder, String, String) AppendKeyValuePair(StringBuilder, String, String)

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

AppendKeyValuePair(StringBuilder, String, String, Boolean) AppendKeyValuePair(StringBuilder, String, String, Boolean) AppendKeyValuePair(StringBuilder, String, String, Boolean) AppendKeyValuePair(StringBuilder, String, String, Boolean)

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

AppendKeyValuePair(StringBuilder, String, String) AppendKeyValuePair(StringBuilder, String, String) AppendKeyValuePair(StringBuilder, String, String) AppendKeyValuePair(StringBuilder, String, String)

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

public:
 static void AppendKeyValuePair(System::Text::StringBuilder ^ builder, System::String ^ keyword, System::String ^ value);
public static void AppendKeyValuePair (System.Text.StringBuilder builder, string keyword, string value);
static member AppendKeyValuePair : System.Text.StringBuilder * string * string -> unit
Public Shared Sub AppendKeyValuePair (builder As StringBuilder, keyword As String, value As String)
Parameters
builder
StringBuilder StringBuilder StringBuilder StringBuilder

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

keyword
String String String String

The key to be added.

value
String String String String

The value for the supplied key.

Examples

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 string AddPooling(string connectionString)
{
    StringBuilder builder = new StringBuilder(connectionString);
    DbConnectionStringBuilder.AppendKeyValuePair(builder, "Pooling", "true");
    return builder.ToString();
}
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

Remarks

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.

See Also

AppendKeyValuePair(StringBuilder, String, String, Boolean) AppendKeyValuePair(StringBuilder, String, String, Boolean) AppendKeyValuePair(StringBuilder, String, String, Boolean) AppendKeyValuePair(StringBuilder, String, String, Boolean)

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

public:
 static void AppendKeyValuePair(System::Text::StringBuilder ^ builder, System::String ^ keyword, System::String ^ value, bool useOdbcRules);
public static void AppendKeyValuePair (System.Text.StringBuilder builder, string keyword, string value, bool useOdbcRules);
static member AppendKeyValuePair : System.Text.StringBuilder * string * string * bool -> unit
Public Shared Sub AppendKeyValuePair (builder As StringBuilder, keyword As String, value As String, useOdbcRules As Boolean)
Parameters
builder
StringBuilder StringBuilder StringBuilder StringBuilder

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

keyword
String String String String

The key to be added.

value
String String String String

The value for the supplied key.

useOdbcRules
Boolean Boolean Boolean Boolean

true to use {} to delimit fields, false to use quotation marks.

Examples

If some process has created a connection string, but now an application must perform a simple modification to that connection string, it might 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, using ODBC rules for quoting values.

public string AddPooling(string connectionString)
{
    StringBuilder builder = new StringBuilder(connectionString);
    DbConnectionStringBuilder.AppendKeyValuePair(builder, "Pooling", "true");
    return builder.ToString();
}
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

Remarks

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 adding 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.

Although most data sources let you delimit fields by using quotation marks, ODBC does not--for ODBC connection strings, you must use curly braces ({}). In order to have the DbConnectionStringBuilder use ODBC rules for delimiting fields, set the useOdbcRules parameter to true.

See Also

Applies to