DbConnectionStringBuilder.ContainsKey(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定 DbConnectionStringBuilder 是否包含特定键。
public:
virtual bool ContainsKey(System::String ^ keyword);
public virtual bool ContainsKey (string keyword);
abstract member ContainsKey : string -> bool
override this.ContainsKey : string -> bool
Public Overridable Function ContainsKey (keyword As String) As Boolean
参数
- keyword
- String
要在 DbConnectionStringBuilder 中定位的键。
返回
如果 DbConnectionStringBuilder 包含具有指定键的项,则为 true
;否则为 false
。
例外
keyword
为空引用(在 Visual Basic 中为 Nothing
)。
示例
static void Main()
{
DbConnectionStringBuilder builder = new DbConnectionStringBuilder();
builder.Add("Provider", "Provider=Microsoft.Jet.OLEDB.4.0");
builder.Add("Data Source", "C:\\ThisExcelWorkbook.xls");
builder.Add("Extended Properties", "Excel 8.0;HDR=Yes;IMEX=1");
// Displays the values in the DbConnectionStringBuilder.
Console.WriteLine("Contents of the DbConnectionStringBuilder:");
Console.WriteLine(builder.ConnectionString);
// Searches for a key.
if (builder.ContainsKey("Data Source"))
{
Console.WriteLine("The collection contains the key \"Data Source\".");
}
else
{
Console.WriteLine("The collection does not contain the key \"Data Source\".");
}
Console.ReadLine();
}
Sub Main()
' The following code example searches for an element in a
' DbConnectionStringBuilder.
Dim builder As New DbConnectionStringBuilder
builder.Add("Provider", "Provider=Microsoft.Jet.OLEDB.4.0")
builder.Add("Data Source", "C:\ThisExcelWorkbook.xls")
builder.Add("Extended Properties", "Excel 8.0;HDR=Yes;IMEX=1")
' Displays the values in the DbConnectionStringBuilder.
Console.WriteLine("Contents of the DbConnectionStringBuilder:")
Console.WriteLine(builder.ConnectionString)
' Searches for a key.
If builder.ContainsKey("Data Source") Then
Console.WriteLine("The collection contains the key ""Data Source"".")
Else
Console.WriteLine("The collection does not contain the key ""Data Source"".")
End If
Console.ReadLine()
End Sub
此代码生成以下输出:
Contents of the DbConnectionStringBuilder:
provider="Provider=Microsoft.Jet.OLEDB.4.0";data
source=C:\MyExcel.xls;extended
properties="Excel 8.0;HDR=Yes;IMEX=1"
The collection contains the key "Data Source".