SqlConnectionStringBuilder.Clear 方法

定义

清除 SqlConnectionStringBuilder 实例的内容。

public:
 override void Clear();
public override void Clear ();
override this.Clear : unit -> unit
Public Overrides Sub Clear ()

示例

下面的示例演示如何调用 Clear 方法。 此示例用一些键/值对填充 SqlConnectionStringBuilder,然后调用 Clear 方法并显示结果。

using Microsoft.Data.SqlClient;

class Program
{
    static void Main()
    {
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
        builder.DataSource = "(local)";
        builder.IntegratedSecurity = true;
        builder.InitialCatalog = "AdventureWorks";
        Console.WriteLine("Initial connection string: " + builder.ConnectionString);

        builder.Clear();
        Console.WriteLine("After call to Clear, count = " + builder.Count);
        Console.WriteLine("Cleared connection string: " + builder.ConnectionString);
        Console.WriteLine();

        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
}

注解

Clear 方法移除 SqlConnectionStringBuilder 中的所有键/值对,并重置所有对应的属性。 这包括将 Count 属性设置为 0,并将 ConnectionString 属性设置为空字符串。

适用于