DbConnectionStringBuilder.AppendKeyValuePair 方法

定义

提供了一种有效而安全的方法,用于将键和值附加到现有的 StringBuilder 对象中。Provides an efficient and safe way to append a key and value to an existing StringBuilder object.

重载

AppendKeyValuePair(StringBuilder, String, String)

提供了一种有效而安全的方法,用于将键和值附加到现有的 StringBuilder 对象中。Provides an efficient and safe way to append a key and value to an existing StringBuilder object.

AppendKeyValuePair(StringBuilder, String, String, Boolean)

提供了一种有效而安全的方法,用于将键和值附加到现有的 StringBuilder 对象中。Provides an efficient and safe way to append a key and value to an existing StringBuilder object.

AppendKeyValuePair(StringBuilder, String, String)

提供了一种有效而安全的方法,用于将键和值附加到现有的 StringBuilder 对象中。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);
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)

参数

builder
StringBuilder

要向其中添加键/值对的 StringBuilderThe StringBuilder to which to add the key/value pair.

keyword
String

要添加的键。The key to be added.

value
String

提供的键的值。The value for the supplied key.

示例

如果某个进程创建了连接字符串,但现在,应用程序必须对该连接字符串执行简单修改,则只需使用对象添加键/值对可能会更有效 StringBuilderIf 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. 开发人员可以调用方法,而不是创建新的,而是 DbConnectionStringBuilder AppendKeyValuePair 传入 StringBuilder 包含所提供的连接字符串的。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

注解

此方法允许开发人员使用 StringBuilder 来创建键/值对的集合,以便在 DbConnectionStringBuilder 添加键/值对时能够利用类中包含的功能,而无需产生创建和维护实例的系统开销 DbConnectionStringBuilderThis 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. AppendKeyValuePair方法正确设置键和值的格式,并将新字符串添加到提供的 StringBuilderThe AppendKeyValuePair method formats the key and value correctly and adds the new string to the supplied StringBuilder.

另请参阅

适用于

AppendKeyValuePair(StringBuilder, String, String, Boolean)

提供了一种有效而安全的方法,用于将键和值附加到现有的 StringBuilder 对象中。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);
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)

参数

builder
StringBuilder

要向其中添加键/值对的 StringBuilderThe StringBuilder to which to add the key/value pair.

keyword
String

要添加的键。The key to be added.

value
String

提供的键的值。The value for the supplied key.

useOdbcRules
Boolean

如果使用 {} 来分隔字段,则为 true;如果使用引号,则为 falsetrue to use {} to delimit fields, false to use quotation marks.

示例

如果某个进程创建了连接字符串,但现在,应用程序必须对该连接字符串执行简单修改,则只需使用对象添加键/值对可能会更有效 StringBuilderIf 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. 开发人员可以调用方法,而不是创建新的,而是 DbConnectionStringBuilder AppendKeyValuePair 传入 StringBuilder 包含所提供的连接字符串的。Instead of creating a new DbConnectionStringBuilder, developers can call the AppendKeyValuePair method, passing in a StringBuilder that contains the supplied connection string. 以下过程显示了此方法的简单示例,使用 ODBC 规则来引用值。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

注解

此方法允许开发人员使用 StringBuilder 来创建键/值对的集合 DbConnectionStringBuilder ,以便在添加键/值对时能够利用类中包含的功能,而无需产生创建和维护实例的系统开销 DbConnectionStringBuilderThis 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. AppendKeyValuePair方法正确设置键和值的格式,并将新字符串添加到提供的 StringBuilderThe AppendKeyValuePair method formats the key and value correctly and adds the new string to the supplied StringBuilder.

尽管大多数数据源都允许使用引号来分隔字段,但 ODBC 不允许 ODBC 连接字符串使用大括号 ({}) 。Although most data sources let you delimit fields by using quotation marks, ODBC does not--for ODBC connection strings, you must use curly braces ({}). 为了使 DbConnectionStringBuilder 使用 ODBC 规则来分隔字段,请将 useOdbcRules 参数设置为 trueIn order to have the DbConnectionStringBuilder use ODBC rules for delimiting fields, set the useOdbcRules parameter to true.

另请参阅

适用于