Generic Data Access
Imports System.Data.Common
Imports System.Configuration
Module GenericDatabaseTest
Public Sub Main()
Dim Factory, Connection, Query As String
Factory = "Factory"
Connection = "Connection"
Query = "Query"
Dim Provider As DbProviderFactory
Provider = DbProviderFactories.GetFactory(Factory)
Dim con As DbConnection = Provider.CreateConnection()
con.ConnectionString = Connection
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")
For Each Row As DataRow In ds.Tables("Orders").Rows
Console.WriteLine(Row("OrderID"))
Next
End Sub
End Module
Related examples in the same category