DbConnectionStringBuilder.ContainsKey(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Determines whether the DbConnectionStringBuilder contains a specific key.
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
Parameters
- keyword
- String
The key to locate in the DbConnectionStringBuilder.
Returns
true
if the DbConnectionStringBuilder contains an entry with the specified key; otherwise false
.
Exceptions
keyword
is a null reference (Nothing
in Visual Basic).
Examples
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
This code produces the following output:
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".
Applies to
See also
Spolupráca s nami v službe GitHub
Zdroj tohto obsahu nájdete v službe GitHub, kde môžete vytvárať a skúmať problémy a žiadosti o prijatie zmien. Ďalšie informácie nájdete v našom sprievodcovi prispievateľom.