Imports System.Data.Common
Imports System.Configuration

Module GenericDatabaseTest

    Public Sub Main()

        'Get all the information from the configuration file.
        Dim Factory, Connection, Query As String
        Factory = ConfigurationManager.AppSettings("Factory")
        Connection = ConfigurationManager.AppSettings("Connection")
        Query = ConfigurationManager.AppSettings("Query")

        ' Get the factory for this provider.
        Dim Provider As DbProviderFactory
        Provider = DbProviderFactories.GetFactory(Factory)

        ' Use the factory to create a connection.
        Dim con As DbConnection = Provider.CreateConnection()
        con.ConnectionString = Connection

        ' Use the factory to create a data adapter
        ' and fill a DataSet.
        Dim Adapter As DbDataAdapter = Provider.CreateDataAdapter
        Adapter.SelectCommand = Provider.CreateCommand()
        Adapter.SelectCommand.Connection = con
        Adapter.SelectCommand.CommandText = Query
        Dim ds As New DataSet
        Adapter.Fill(ds, "Orders")

        ' Display the retrieved information.
        For Each Row As DataRow In ds.Tables("Orders").Rows
            Console.WriteLine(Row("OrderID"))
        Next

        Console.ReadLine()
    End Sub

End Module
