SqlConnectionStringBuilder.Clear 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
清除 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 屬性設定為空字串。
適用於
另請參閱
- ADO.NET 中的連接字串
- ADO.NET 概觀 \(部分機器翻譯\)