OdbcConnectionStringBuilder.Clear Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menghapus konten instans OdbcConnectionStringBuilder .
public:
override void Clear();
public override void Clear ();
override this.Clear : unit -> unit
Public Overrides Sub Clear ()
Contoh
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
Keterangan
Metode ini Clear menghapus semua pasangan kunci/nilai dari OdbcConnectionStringBuilder dan mengatur ulang Driver properti dan Dsn ke nilai defaultnya. Metode ini Clear juga mengatur properti ke Count 0 dan ConnectionString properti ke string kosong.
Berlaku untuk
Lihat juga
Berkolaborasi dengan kami di GitHub
Sumber untuk konten ini dapat ditemukan di GitHub, yang juga dapat Anda gunakan untuk membuat dan meninjau masalah dan menarik permintaan. Untuk informasi selengkapnya, lihat panduan kontributor kami.