SqlConnectionStringBuilder.Clear Method

Definition

清除 SqlConnectionStringBuilder 实例的内容。Clears the contents of the SqlConnectionStringBuilder instance.

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

Examples

下面的示例演示如何调用 Clear 方法。The following example demonstrates calling the Clear method. 此示例用一些键/值对填充 SqlConnectionStringBuilder,然后调用 Clear 方法并显示结果。This example populates the SqlConnectionStringBuilder with some key/value pairs, and then calls the Clear method and shows the results.

using System.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();
    }
}
Imports System.Data.SqlClient
    
Module Module1
    Sub Main()
        Dim builder As 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()
    End Sub
End Module

Remarks

Clear 方法移除 SqlConnectionStringBuilder 中的所有键/值对,并重置所有对应的属性。The Clear method removes all key/value pairs from the SqlConnectionStringBuilder, and resets all corresponding properties. 这包括将 Count 属性设置为 0,并将 ConnectionString 属性设置为空字符串。This includes setting the Count property to 0, and setting the ConnectionString property to an empty string.

Applies to

See also