OdbcConnectionStringBuilder.Clear Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Clears the contents of the OdbcConnectionStringBuilder instance.

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

public override void Clear()

The Clear method removes all key/value pairs from the OdbcConnectionStringBuilder and resets the Driver and Dsn properties to their default values. The Clear method also sets the Count property to 0 and the T:System.Data.Odbc.OdbcConnectionStringBuilder.ConnectionString property to an empty string.

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

.NET Framework
Available since 2.0
Return to top
Show: