Export (0) Print
Expand All

DbConnectionStringBuilder.Remove Method

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

Namespace: System.Data.Common
Assembly: System.Data (in system.data.dll)

public virtual bool Remove (
	string keyword
)
public boolean Remove (
	String keyword
)
public function Remove (
	keyword : String
) : boolean
Not applicable.

Parameters

keyword

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

Return Value

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

Exception typeCondition

ArgumentNullException

keyword is null (Nothing in Visual Basic)

NotSupportedException

The DbConnectionStringBuilder is read-only, or the DbConnectionStringBuilder has a fixed size.

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

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

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

static void TryRemove(DbConnectionStringBuilder builder, string itemToRemove)
{
    if (builder.Remove(itemToRemove))
    {
        Console.WriteLine(@"Removed '{0}'", itemToRemove);
    }
    else
    {
        Console.WriteLine(@"Unable to remove '{0}'", itemToRemove);
    }
    Console.WriteLine(builder.ConnectionString);
}

This sample displays the following output:

Removed 'Provider'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Unable to remove 'User ID'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Removed 'DATA SOURCE'
jet oledb:system database=system.mdw

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft