OdbcConnectionStringBuilder.Clear 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
清除 OdbcConnectionStringBuilder 執行個體的內容。
public:
override void Clear();
public override void Clear ();
override this.Clear : unit -> unit
Public Overrides Sub Clear ()
範例
using System.Data.Odbc;
class Program
{
static void Main()
{
OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();
// Call the Add method to explicitly add key/value
// pairs to the internal collection.
builder.Driver = "Microsoft Excel Driver (*.xls)";
builder["Dbq"] = "C:\\Data.xls";
builder["DriverID"] = "790";
builder["DefaultDir"] = "C:\\";
// Dump the contents of the "filled-in" OdbcConnectionStringBuilder
// to the Console window:
DumpBuilderContents(builder);
// Clear current values and reset known keys to their
// default values.
builder.Clear();
// Dump the contents of the newly emptied OdbcConnectionStringBuilder
// to the console window.
DumpBuilderContents(builder);
Console.WriteLine("Press Enter to continue.");
Console.ReadLine();
}
private static void DumpBuilderContents(OdbcConnectionStringBuilder builder)
{
Console.WriteLine("=================");
Console.WriteLine("builder.ConnectionString = " + builder.ConnectionString);
foreach (string key in builder.Keys)
{
Console.WriteLine(key + "=" + builder[key].ToString());
}
}
}
Imports System.Data.Odbc
Module Module1
Sub Main()
Dim builder As New OdbcConnectionStringBuilder()
' Call the Add method to explicitly add key/value
' pairs to the internal collection.
builder.Driver = "Microsoft Excel Driver (*.xls)"
builder("Dbq") = "C:\Data.xls"
builder("DriverID") = "790"
builder("DefaultDir") = "C:\"
' Dump the contents of the "filled-in" OdbcConnectionStringBuilder
' to the console window.
DumpBuilderContents(builder)
' Clear current values and reset known keys to their
' default values.
builder.Clear()
' Dump the contents of the newly emptied
' OdbcConnectionStringBuilder
' to the console window.
DumpBuilderContents(builder)
Console.WriteLine("Press Enter to continue.")
Console.ReadLine()
End Sub
Private Sub DumpBuilderContents(ByVal builder As OdbcConnectionStringBuilder)
Console.WriteLine("=================")
Console.WriteLine("builder.ConnectionString = " & builder.ConnectionString)
For Each key As String In builder.Keys
Console.WriteLine(key & "=" & builder.Item(key).ToString)
Next
End Sub
End Module
備註
方法Clear會從 OdbcConnectionStringBuilder 中移除所有索引鍵/值組,並將 和 Dsn 屬性重設為Driver預設值。 方法 Clear 也會將 Count 屬性設定為 0,並將 ConnectionString 屬性設定為空字串。