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 中删除所有键/值对, Driver 并将 和 Dsn 属性重置为其默认值。 方法 Clear 还将 属性设置为 Count 0,并将 ConnectionString 属性设置为空字符串。