vb.net adodb.connection code example

Example: vb.net connection

'Its VB.net Code
Imports System.Data.SqlClient
Module ComModul
#Region "Var"
    Public dbCon = New ADODB.Connection
    Public dbRS = New ADODB.Recordset
    Public strProvider As String = "Microsoft.ACE.OLEDB.12.0" 'or an other provider
    Public strDBPath As String = "path"
#End Region
    'Öffnet eine Verbindung zu einer Datenbank
    'open connection to Database. You can use it for an coonection command too
#Region "DB Connection"
    Public Function DB_Connect(ByRef dbCon As ADODB.Connection, Optional ByVal strExe As String = "") As Boolean
        Try
            If strExe = "" Then
                dbCon.Provider = strProvider
                dbCon.Open(strDBPath)
            Else
                dbCon.Execute(strExe)
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString())
        End Try
        Return False
    End Function
#End Region
    'Öffnet ein Recordset (Nur mit bestehner verbindung zu einer datenquelle aufrufen)
    'Open Recordset, need an SQL Statmend like "strSQL as String = "SELECT * FROM TABLE"".Dont forget to close the Recordset
    'and set it to Nothing -----> dbRS.close --------> dbRS = Nothing
#Region "Recordset"
    Public Function Open_RS(ByVal strSQL As String, ByRef dbCon As ADODB.Connection, ByRef dbRS As ADODB.Recordset) As Boolean
        Try
            If strSQL = "" Then
                Throw New AggregateException("Sql")
            End If
            dbRS = New ADODB.Recordset
            dbRS.Open(strSQL, dbCon)
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
        Return False
    End Function
#End Region
End Module