OleDbConnectionStringBuilder.Clear Metoda

Definice

Vymaže obsah OleDbConnectionStringBuilder instance.

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

Příklady

Následující příklad ukazuje účinek volání Clear metody . Tento příklad naplní OleDbConnectionStringBuilder objekt několika páry klíč/hodnota a pak zavolá metodu Clear a zobrazí výsledky.

Poznámka

Tento příklad obsahuje heslo, které ukazuje, jak OleDbConnectionStringBuilder funguje s připojovacími řetězci. Ve vašich aplikacích doporučujeme používat ověřování systému Windows. Pokud je nutné použít heslo, nevkládejte do své aplikace pevně zakódované heslo.

using System.Data.OleDb;

class Program
{
    static void Main()
    {
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder();
        builder.ConnectionString = @"Data Source=c:\Sample.mdb";

        // Call the Add method to explicitly add key/value
        // pairs to the internal collection.
        builder.Add("Provider", "Microsoft.Jet.Oledb.4.0");
        builder.Add("Jet OLEDB:Database Password", "MyPassword!");
        builder.Add("Jet OLEDB:System Database", @"C:\Workgroup.mdb");

        // set up row-level locking.
        builder.Add("Jet OLEDB:Database Locking Mode", 1);

        // Dump the contents of the "filled-in"
        // OleDbConnectionStringBuilder
        // 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
        // OleDbConnectionStringBuilder
        // to the console window.
        DumpBuilderContents(builder);

        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }

    private static void DumpBuilderContents(OleDbConnectionStringBuilder builder)
    {
        Console.WriteLine("=================");
        Console.WriteLine("builder.ConnectionString = " + builder.ConnectionString);
        foreach (string key in builder.Keys)
        {
            Console.WriteLine(key + "=" + builder[key].ToString());
        }
    }
}
Imports System.Data.OleDb    

Module Module1
  Sub Main()
    Dim builder As New OleDbConnectionStringBuilder()
    builder.ConnectionString = "Data Source=C:\Sample.mdb"

    ' Call the Add method to explicitly add key/value
    ' pairs to the internal collection.
    builder.Add("Provider", "Microsoft.Jet.Oledb.4.0")
    builder.Add("Jet OLEDB:Database Password", "MyPassword!")
    builder.Add("Jet OLEDB:System Database", "C:\Workgroup.mdb")

    ' Set up row-level locking.
    builder.Add("Jet OLEDB:Database Locking Mode", 1)

    ' Dump the contents of the "filled-in" OleDbConnectionStringBuilder
    ' to the console window.
    DumpBuilderContents(builder)

    ' Clear current values and reset known keywords to their
    ' default values.
    builder.Clear()

    ' Dump the contents of the newly emptied 
    ' OleDbConnectionStringBuilder
    ' to the console window.
    DumpBuilderContents(builder)

    Console.WriteLine("Press Enter to continue.")
    Console.ReadLine()
  End Sub

  Private Sub DumpBuilderContents(ByVal builder As OleDbConnectionStringBuilder)
    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

Poznámky

Metoda Clear odebere všechny páry klíč/hodnota z OleDbConnectionStringBuildera resetuje všechny odpovídající vlastnosti na jejich výchozí hodnoty. To zahrnuje nastavení Count vlastnosti na hodnotu 0 a nastavení ConnectionString vlastnosti na prázdný řetězec.

Platí pro

Viz také