本文整理匯總了VB.NET中System.Data.Common.DbConnectionStringBuilder.TryGetValue方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET DbConnectionStringBuilder.TryGetValue方法的具體用法?VB.NET DbConnectionStringBuilder.TryGetValue怎麽用?VB.NET DbConnectionStringBuilder.TryGetValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.Common.DbConnectionStringBuilder
的用法示例。
在下文中一共展示了DbConnectionStringBuilder.TryGetValue方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
Sub Main()
Dim builder As New DbConnectionStringBuilder
builder.ConnectionString = _
"Provider=sqloledb;Data Source=192.168.168.1,1433;" & _
"Network Library=DBMSSOCN;Initial Catalog=pubs;" & _
"Integrated Security=SSPI;"
' Call TryGetValue method for multiple
' key names.
DisplayValue(builder, "Provider")
DisplayValue(builder, "DATA SOURCE")
DisplayValue(builder, "InvalidKey")
DisplayValue(builder, Nothing)
Console.ReadLine()
End Sub
Private Sub DisplayValue( _
ByVal builder As DbConnectionStringBuilder, ByVal key As String)
Dim value As Object
' Although TryGetValue handles missing keys,
' it doesn't handle passing in a null (Nothing in Visual Basic)
' key. This example traps for that particular error, but
' bubbles any other unknown exceptions back out to the
' caller.
Try
If builder.TryGetValue(key, value) Then
Console.WriteLine("{0}={1}", key, value)
Else
Console.WriteLine("Unable to retrieve value for '{0}'", key)
End If
Catch ex As ArgumentNullException
Console.WriteLine("Unable to retrieve value for null key.")
End Try
End Sub