DbConnectionStringBuilder.Remove(String) Méthode

Définition

Supprime l'entrée contenant la clé spécifiée dans l'instance de DbConnectionStringBuilder.Removes the entry with the specified key from the DbConnectionStringBuilder instance.

public:
 virtual bool Remove(System::String ^ keyword);
public virtual bool Remove (string keyword);
abstract member Remove : string -> bool
override this.Remove : string -> bool
Public Overridable Function Remove (keyword As String) As Boolean

Paramètres

keyword
String

Clé de la paire clé/valeur à supprimer de la chaîne de connexion dans DbConnectionStringBuilder.The key of the key/value pair to be removed from the connection string in this DbConnectionStringBuilder.

Retours

true si la clé existait dans la chaîne de connexion et a été supprimée ; false si la clé n’existait pas.true if the key existed within the connection string and was removed; false if the key did not exist.

Exceptions

keyword a la valeur Null (Nothing en Visual Basic).keyword is null (Nothing in Visual Basic)

DbConnectionStringBuilder est en lecture seule ou DbConnectionStringBuilder est de taille fixe.The DbConnectionStringBuilder is read-only, or the DbConnectionStringBuilder has a fixed size.

Exemples

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);
}
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")
    Console.ReadLine()
End Sub

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

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

Cet exemple affiche la sortie suivante :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  

Remarques

Étant donné Remove que la méthode retourne une valeur qui indique sa réussite, il n’est pas nécessaire de rechercher la clé avant d’essayer de supprimer la paire clé/ DbConnectionStringBuilder valeur de l’instance.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.

S’applique à

Voir aussi