The Microsoft site allows you to pick a language (C# or VB, and sometimes others) via a drop-down at the top-right of the page.
In this case, if you select VB on that page the examples are:
Code:
' This example assumes a reference to System.Data.Common.
Private Shared Function GetProviderFactoryClasses() As DataTable
' Retrieve the installed providers and factories.
Dim table As DataTable = DbProviderFactories.GetFactoryClasses()
' Display each row and column value.
Dim row As DataRow
Dim column As DataColumn
For Each row In table.Rows
For Each column In table.Columns
Console.WriteLine(row(column))
Next
Next
Return table
End Function
Code:
' Retrieve a connection string by specifying the providerName.
' Assumes one connection string per provider in the config file.
Private Shared Function GetConnectionStringByProvider( _
ByVal providerName As String) As String
'Return Nothing on failure.
Dim returnValue As String = Nothing
' Get the collection of connection strings.
Dim settings As ConnectionStringSettingsCollection = _
ConfigurationManager.ConnectionStrings
' Walk through the collection and return the first
' connection string matching the providerName.
If Not settings Is Nothing Then
For Each cs As ConnectionStringSettings In settings
If cs.ProviderName = providerName Then
returnValue = cs.ConnectionString
Exit For
End If
Next
End If
Return returnValue
End Function
Code:
' Given a provider, create a DbProviderFactory and DbConnection.
' Returns a DbConnection on success; Nothing on failure.
Private Shared Function CreateDbConnection( _
ByVal providerName As String, ByVal connectionString As String) _
As DbConnection
' Assume failure.
Dim connection As DbConnection = Nothing
' Create the DbProviderFactory and DbConnection.
If Not connectionString Is Nothing Then
Try
Dim factory As DbProviderFactory = _
DbProviderFactories.GetFactory(providerName)
connection = factory.CreateConnection()
connection.ConnectionString = connectionString
Catch ex As Exception
' Set the connection to Nothing if it was created.
If Not connection Is Nothing Then
connection = Nothing
End If
Console.WriteLine(ex.Message)
End Try
End If
' Return the connection.
Return connection
End Function
...which in this case are near enough identical to what you came up with.