共用方式為


OleDbConnectionStringBuilder.Remove(String) 方法

定義

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

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

參數

keyword
String

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

傳回

如果連接字串之內有索引鍵而且已經移除,則為 true,如果沒有索引鍵,則為 false

例外狀況

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

範例

下列範例會 OleDbConnectionStringBuilder 建立 ,並示範 方法的行為 Remove

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);
    }
}
Imports System.Data.OleDb    

Module Module1

  Sub Main()
    Dim builder As 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 is not 
    ' case sensitive.
    TryRemove(builder, "DATA SOURCE")

    Console.WriteLine("Press Enter to continue.")
    Console.ReadLine()
  End Sub

  Sub TryRemove(ByVal builder As OleDbConnectionStringBuilder, _
      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

End Module

備註

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

適用於

另請參閱