OdbcConnectionStringBuilder.ContainsKey(String) 方法

定义

确定 OdbcConnectionStringBuilder 是否包含特定键。

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

参数

keyword
String

要在 OdbcConnectionStringBuilder 中定位的键。

返回

如果 OdbcConnectionStringBuilder 包含具有指定键的元素,则为 true;否则为 false

例外

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

示例

以下示例创建一个 OdbcConnectionStringBuilder 实例,设置其一些属性,然后尝试通过调用 ContainsKey 方法来确定对象中是否存在各种键。

using System.Data.Odbc;

class Program
{
    static void Main()
    {
        OdbcConnectionStringBuilder  builder = new OdbcConnectionStringBuilder();
        builder.Driver = "Microsoft Visual FoxPro Driver";
        builder["SourceType"] = "DBC";

        // Keys that you have provided return true.
        Console.WriteLine(builder.ContainsKey("SourceType"));

        // Comparison is case insensitive.
        Console.WriteLine(builder.ContainsKey("sourcetype"));

        // Keys added by the provider return false. This method
        // only examines keys added explicitly.
        Console.WriteLine(builder.ContainsKey("DNS"));

        // Keys that do not exist return false.
        Console.WriteLine(builder.ContainsKey("MyKey"));

        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
}
Imports System.Data.Odbc    

Module Module1
  Sub Main()
    Dim builder As New OdbcConnectionStringBuilder()
    builder.Driver = "Microsoft Visual FoxPro Driver"
    builder("SourceType") = "DBC"

    ' Keys you have provided return true.
    Console.WriteLine(builder.ContainsKey("SourceType"))

    ' Comparison is case insensitive.
    Console.WriteLine(builder.ContainsKey("sourcetype"))

    ' Keys added by the provider return false. This method
    ' only examines keys added explicitly.
    Console.WriteLine(builder.ContainsKey("DNS"))

    ' Keys that do not exist return false.
    Console.WriteLine(builder.ContainsKey("MyKey"))

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

适用于

另请参阅