OleDbConnectionStringBuilder.Remove(String) Method

Definition

Removes the entry with the specified key from the OleDbConnectionStringBuilder instance.

public override bool Remove (string keyword);

Parameters

keyword
String

The key of the key/value pair to be removed from the connection string in this OleDbConnectionStringBuilder.

Returns

true if the key existed within the connection string and was removed, false if the key did not exist.

Exceptions

keyword is null (Nothing in Visual Basic).

Examples

The following example creates a OleDbConnectionStringBuilder and demonstrates the behavior of the Remove method.

using System.Data.OleDb;

class Program
{
    static void Main()
    {
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder();
        builder.ConnectionString =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Sample.mdb;" +
            "Jet OLEDB:System Database=C:\\system.mdw;";

        Console.WriteLine(builder.ConnectionString);

        // Try to remove an existing item.
        TryRemove(builder, "Provider");

        // Try to remove a nonexistent item.
        TryRemove(builder, "User ID");

        // try to remove an existing item,
        // demonstrating that the search isn't
        // case sensitive.
        TryRemove(builder, "DATA SOURCE");

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

    static void TryRemove(OleDbConnectionStringBuilder builder,
        string itemToRemove)
    {

        if (builder.Remove(itemToRemove))
        {
            Console.WriteLine("Removed '{0}'", itemToRemove);
        }
        else
        {
            Console.WriteLine("Unable to remove '{0}'", itemToRemove);
        }
        Console.WriteLine(builder.ConnectionString);
    }
}

Remarks

Because the Remove method returns a value that indicates its success, it is not required to look for the existence of a key before trying to remove the key/value pair from the OleDbConnectionStringBuilder instance.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also