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 实例中删除键/值对之前,不需要查找键是否存在。

适用于

另请参阅