SqlConnectionStringBuilder.ContainsKey(String) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menentukan apakah SqlConnectionStringBuilder berisi kunci tertentu.
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
Parameter
- keyword
- String
Kunci untuk menemukan di SqlConnectionStringBuilder.
Mengembalikan
true
SqlConnectionStringBuilder jika berisi elemen yang memiliki kunci yang ditentukan; jika tidak, false
.
Pengecualian
keyword
null (Nothing
dalam Visual Basic)
Contoh
Contoh berikut membuat instans SqlConnectionStringBuilder , mengatur beberapa propertinya, lalu mencoba menentukan apakah berbagai kunci ada dalam objek dengan memanggil metode ContainsKey .
using System.Data.SqlClient;
class Program
{
static void Main()
{
SqlConnectionStringBuilder builder =
new SqlConnectionStringBuilder(GetConnectionString());
Console.WriteLine("Connection string = " + builder.ConnectionString);
// Keys you have provided return true.
Console.WriteLine(builder.ContainsKey("Server"));
// Comparison is case insensitive, and synonyms
// are automatically converted to their "well-known"
// names.
Console.WriteLine(builder.ContainsKey("Database"));
// Keys that are valid but have not been set return true.
Console.WriteLine(builder.ContainsKey("Max Pool Size"));
// Keys that do not exist return false.
Console.WriteLine(builder.ContainsKey("MyKey"));
Console.WriteLine("Press Enter to continue.");
Console.ReadLine();
}
private static string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "Server=(local);Integrated Security=SSPI;" +
"Initial Catalog=AdventureWorks";
}
}
Imports System.Data.SqlClient
Module Module1
Sub Main()
Dim builder As _
New SqlConnectionStringBuilder(GetConnectionString())
Console.WriteLine("Connection string = " & builder.ConnectionString)
' Keys you have provided return true.
Console.WriteLine(builder.ContainsKey("Server"))
' Comparison is case insensitive, and synonyms
' are automatically converted to their "well-known"
' names.
Console.WriteLine(builder.ContainsKey("Database"))
' Keys that are valid but have not been set return true.
Console.WriteLine(builder.ContainsKey("Max Pool Size"))
' Keys that do not exist return false.
Console.WriteLine(builder.ContainsKey("MyKey"))
Console.WriteLine("Press Enter to continue.")
Console.ReadLine()
End Sub
Private Function GetConnectionString() As String
' To avoid storing the connection string in your code,
' you can retrieve it from a configuration file.
Return "Server=(local);Integrated Security=SSPI;" & _
"Initial Catalog=AdventureWorks"
End Function
End Module
Contoh ini menampilkan output berikut di jendela konsol:
Connection string = Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True
True
True
True
False
Keterangan
SqlConnectionStringBuilder Karena berisi kumpulan ukuran tetap dari pasangan kunci/nilai, ContainsKey metode hanya menentukan apakah nama kunci tertentu valid.