OleDbConnectionStringBuilder.Remove Method (String)

 

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

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

public override bool Remove(
	string keyword
)

Parameters

keyword
Type: System.String

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

Return Value

Type: System.Boolean

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

Exception Condition
ArgumentNullException

keyword is null (Nothing in Visual Basic).

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.

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

.NET Framework
Available since 2.0
Return to top
Show: