共用方式為


DbConnectionStringBuilder.Remove(String) 方法

定義

DbConnectionStringBuilder 執行個體移除具有指定之索引鍵的項目。

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

參數

keyword
String

要從這個 DbConnectionStringBuilder 的連接字串中移除之索引鍵/值組的索引鍵。

傳回

如果索引鍵存在於連接字串中且遭到移除,則為 true;如果索引鍵不存在,則為 false

例外狀況

keyword 為 null (在 Visual Basic 中為 Nothing)。

DbConnectionStringBuilder 是唯讀的,或 DbConnectionStringBuilder 具有固定的大小。

範例

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

這個範例會顯示下列輸出:

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

備註

Remove因為方法會傳回指出其成功的值,所以在嘗試從 DbConnectionStringBuilder 實例移除索引鍵/值組之前,不需要尋找索引鍵。

適用於

另請參閱