Clear Method
Collapse the table of content
Expand the table of content

OleDbConnectionStringBuilder.Clear Method ()

 

Clears the contents of the OleDbConnectionStringBuilder instance.

Namespace:   System.Data.OleDb
Assembly:  System.Data (in System.Data.dll)

public override void Clear()

The Clear method removes all key/value pairs from the OleDbConnectionStringBuilder, and resets all corresponding properties to their default values. This includes setting the Count property to 0, and setting the ConnectionString property to an empty string.

The following example demonstrates the effect of calling the Clear method. This example populates the OleDbConnectionStringBuilder with some key/value pairs, and then calls the Clear method and shows the results.

System_CAPS_noteNote

This example includes a password to demonstrate how OleDbConnectionStringBuilder works with connection strings. In your applications, we recommend that you use Windows Authentication. If you must use a password, do not include a hard-coded password in your application.

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());
        }
    }
}

.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft