共用方式為


SqlConnectionStringBuilder.Clear 方法

定義

清除 SqlConnectionStringBuilder 執行個體的內容。

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

範例

下列程式碼範例示範如何呼叫 Clear 方法。 此範例會以某些索引鍵/值組填入 SqlConnectionStringBuilder,然後呼叫 Clear 方法並顯示結果。

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

備註

Clear 方法會從 SqlConnectionStringBuilder 移除所有的索引鍵/值組,並重設所有對應的屬性。 其中包括將 Count 屬性設定為 0 以及將 ConnectionString 屬性設定為空字串。

適用於

另請參閱