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 Overridable Function Remove ( _
	keyword As String _
) As Boolean


Type: System.String

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

Return Value

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


keyword is null (Nothing in Visual Basic)


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.

Sub Main()
    Dim builder As 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")
End Sub 

Sub TryRemove(ByVal builder As DbConnectionStringBuilder, _
    ByVal itemToRemove As String)

    If builder.Remove(itemToRemove) Then
        Console.WriteLine("Removed '{0}'", itemToRemove)
        Console.WriteLine("Unable to remove '{0}'", itemToRemove)
    End If
End Sub

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
jet oledb:system database=system.mdw

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft