VB.Net Database Connection Class for MS SQL & Access, Oracle

Are you looking a database connection class to connect the database using VB.Net try this code. I found this code DB Connection class when started coding in VB.Net by searching to the internet. This code is useful for student or newbies programmer to experiment this class how to connect database, Create, Delete, Retrieve or Delete record. See also the sample usage how to use this class then try it in your own learning process... it’s easy to used.

======================
clsDbConnection.vb
======================
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Data.Odbc
Public Class clsDbConnection
    ''' <summary>
    ''' Change the Provider from Line Below and Set the New Connection String 
    ''' </summary>
    ''' <remarks></remarks>
    Private Const _Factory As GetFactory = GetFactory.OleDb
    'Public cnOdbc As OdbcConnection
    ''' <summary>
    ''' Change the ConnectionString According to Database
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Public Shared CONSTRING As String = "PROVIDER=SQLOLEDB;Password=pass_1234;User ID=sa;Data Source=192.111.1.111;Initial Catalog=MyDatabase;Connection Timeout=0"
    Public Shared CONSTRING_MDB As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\192.111.1.111\MDB Data\Sample.mdb;Jet OLEDB:Database Password=pass_1234"
    ''' <summary>
    ''' Gets all available Data Provider.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Shared Function GetAllFactories() As DataTable
        Return DbProviderFactories.GetFactoryClasses
    End Function
    ''' <summary>
    ''' Set Data Provider.
    ''' </summary>
    ''' <param name="oGetFactory"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Shared Function GetFactoryBySelection(ByVal oGetFactory As GetFactory) As String
        Select Case CType(oGetFactory, GetFactory)
            Case GetFactory.Odbc
                Return "System.Data.Odbc"
            Case GetFactory.OleDb
                Return "System.Data.OleDb"
            Case GetFactory.SqlClient
                Return "System.Data.SqlClient"
        End Select
        Return ""
    End Function
    ''' <summary>
    ''' Executes a Transact-SQL statement against the connection and returns the number of rows affected.
    ''' </summary>
    ''' <param name="connString">Set connection string. </param>
    ''' <param name="cmdType">Set a value indicating how the DbCommand.CommandText property is to be interpreted.</param>
    ''' <param name="cmdText">Set the Transact-SQL statement or stored procedure to execute at the data source.</param>
    ''' <param name="cmdParms">Set parameter collection.  </param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ExecuteNonQuery(ByVal connString As String, ByVal cmdType As CommandType, ByVal cmdText As String, ByVal cmdParms As ParameterBuilder()) As Integer
        Dim oProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory(GetFactoryBySelection(_Factory))
        Dim Con As DbConnection = oProviderFactory.CreateConnection
        Dim cmd As DbCommand = Con.CreateCommand
        Dim trans As DbTransaction = Nothing
        Try
            Con.ConnectionString = connString
            cmd.Connection = Con
            cmd.CommandText = cmdText
            cmd.Parameters.Clear()
            cmd.CommandType = cmdType
            If Not (IsNothing(cmdParms)) Then
                Dim parmBuilder As ParameterBuilder
                For Each parmBuilder In cmdParms
                    Dim Param As DbParameter = cmd.CreateParameter
                    Param.ParameterName = CType(parmBuilder, ParameterBuilder).ParamName
                    Param.SourceVersion = CType(parmBuilder, ParameterBuilder).SourceVersion
                    Param.SourceColumn = CType(parmBuilder, ParameterBuilder).SourceColumn
                    Param.SourceColumnNullMapping = CType(parmBuilder, ParameterBuilder).SourceColumnNullMapping
                    Param.Size = CType(parmBuilder, ParameterBuilder).Size
                    Param.Direction = CType(parmBuilder, ParameterBuilder).Direction
                    Param.DbType = CType(parmBuilder, ParameterBuilder).DbType
                    Param.Value = CType(parmBuilder, ParameterBuilder).Value
                    cmd.Parameters.Add(Param)
                Next
            End If
            Con.Open()
            trans = Con.BeginTransaction
            cmd.Transaction = trans
            Dim val As Integer = cmd.ExecuteNonQuery()
            cmd.Parameters.Clear()
            trans.Commit()
            Return val
        Catch ex As DbException
            trans.Rollback()
            Throw New Exception("DB Exception " & ex.Message)
        Catch exx As Exception
            trans.Rollback()
            Throw New Exception("ExecuteNonQuery Function", exx)
        Finally
            Con.Close()
            Con.Dispose()
            Con = Nothing
            cmd.Dispose()
            cmd = Nothing
            cmdParms = Nothing
            oProviderFactory = Nothing
        End Try
    End Function
    ''' <summary>
    ''' ExecuteScalar
    ''' </summary>
    ''' <param name="connString"></param>
    ''' <param name="cmdType"></param>
    ''' <param name="cmdText"></param>
    ''' <param name="cmdParms"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ExecuteScalar(ByVal connString As String, ByVal cmdType As CommandType, ByVal cmdText As String, Optional ByVal cmdParms As ParameterBuilder() = Nothing) As Object
        Dim oProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory(GetFactoryBySelection(_Factory))
        Dim Con As DbConnection = oProviderFactory.CreateConnection
        Dim cmd As DbCommand = Con.CreateCommand
        Con.ConnectionString = connString
        Try
            PrepareCommand(cmd, Con, cmdType, cmdText, cmdParms)
            Dim val As Object = cmd.ExecuteScalar()
            cmd.Parameters.Clear()
            Return val
        Catch ex As DbException
            Throw New Exception("SQL Exception ", ex)
        Catch exx As Exception
            Throw New Exception("ExeculateScalar", exx)
        Finally
            Con.Close()
            Con.Dispose()
            Con = Nothing
            cmd.Dispose()
            cmd = Nothing
            oProviderFactory = Nothing
        End Try
    End Function
    ''' <summary>
    ''' Executes Table
    ''' </summary>
    ''' <param name="connString">Set connection string. </param>
    ''' <param name="cmdType">Set a value indicating how the DbCommand.CommandText property is to be interpreted.</param>
    ''' <param name="cmdText">Set the Transact-SQL statement or stored procedure to execute at the data source.</param>
    ''' <param name="cmdParms">Set parameter collection.  </param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ExecuteTable(ByVal connString As String, ByVal cmdType As CommandType, ByVal cmdText As String, Optional ByVal cmdParms As ParameterBuilder() = Nothing) As DataTable
        Dim oProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory(GetFactoryBySelection(_Factory))
        Dim oDataAdapter As DbDataAdapter
        Dim Con As DbConnection = oProviderFactory.CreateConnection
        Dim cmd As DbCommand
        Try
            Con.ConnectionString = connString
            cmd = Con.CreateCommand
            cmd.CommandTimeout = 6000
            PrepareCommand(cmd, Con, cmdType, cmdText, cmdParms)
            oDataAdapter = oProviderFactory.CreateDataAdapter
            Dim oDataTable As New DataTable
            oDataAdapter.SelectCommand = cmd
            oDataAdapter.Fill(oDataTable)
            cmd.Parameters.Clear()
            Return oDataTable
        Catch ex As DbException
            Throw New Exception("DB Exception ", ex)
        Catch exx As Exception
            Throw New Exception("ExecuteTable Exception :", exx)
        Finally
            Con.Close()
            Con.Dispose()
            Con = Nothing
            cmd.Dispose()
            cmd = Nothing
            oDataAdapter.Dispose()
            oDataAdapter = Nothing
            oProviderFactory = Nothing
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="connString"></param>
    ''' <param name="cmdType"></param>
    ''' <param name="cmdText"></param>
    ''' <param name="cmdParms"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ExecuteDataSet(ByVal connString As String, ByVal cmdType As CommandType, ByVal cmdText As String, Optional ByVal cmdParms As ParameterBuilder() = Nothing) As DataSet
        Dim oProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory(GetFactoryBySelection(_Factory))
        Dim con As DbConnection = oProviderFactory.CreateConnection
        Dim oDataAdapter As DbDataAdapter
        Dim oDataSet As New DataSet
        Dim cmd As DbCommand
        Try
            con.ConnectionString = connString
            cmd = con.CreateCommand
            PrepareCommand(cmd, con, cmdType, cmdText, cmdParms)
            oDataAdapter = oProviderFactory.CreateDataAdapter
            oDataAdapter.SelectCommand = cmd
            oDataAdapter.Fill(oDataSet)
            cmd.Parameters.Clear()
            Return oDataSet
        Catch ex As DbException
            Throw New Exception("SQL Exception ", ex)
        Catch exx As Exception
            Throw New Exception("Execute DataSet", exx)
        Finally
            con.Close()
            con.Dispose()
            con = Nothing
            cmd = Nothing
            oDataAdapter = Nothing
            oProviderFactory = Nothing
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="cmd">A System.Data.Common.DbCommand that represents the active command</param>
    ''' <param name="conn">A System.Data.Common.DbConnection that represents the connection to instance.</param>
    ''' <param name="cmdType">Set a value indicating how the DbCommand.CommandText property is to be interpreted.</param>
    ''' <param name="cmdText">Set the Transact-SQL statement or stored procedure to execute at the data source.</param>
    ''' <param name="cmdParms">Set parameter collection.  </param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function PrepareCommand(ByRef cmd As DbCommand, ByRef conn As DbConnection, ByRef cmdType As CommandType, ByRef cmdText As String, ByRef cmdParms As ParameterBuilder()) As Boolean
        If Not conn.State = ConnectionState.Open Then
            conn.Open()
        End If
        Try
            cmd.Connection = conn
            cmd.CommandText = cmdText
            cmd.Parameters.Clear()
            cmd.CommandType = cmdType
            If Not (IsNothing(cmdParms)) Then
                Dim parm As DbParameter = Nothing
                Dim parmBuilder As ParameterBuilder
                For Each parmBuilder In cmdParms
                    Dim Param As DbParameter = cmd.CreateParameter
                    Param.ParameterName = CType(parmBuilder, ParameterBuilder).ParamName
                    Param.SourceVersion = CType(parmBuilder, ParameterBuilder).SourceVersion
                    Param.SourceColumn = CType(parmBuilder, ParameterBuilder).SourceColumn
                    Param.SourceColumnNullMapping = CType(parmBuilder, ParameterBuilder).SourceColumnNullMapping
                    Param.Size = CType(parmBuilder, ParameterBuilder).Size
                    Param.Direction = CType(parmBuilder, ParameterBuilder).Direction
                    Param.DbType = CType(parmBuilder, ParameterBuilder).DbType
                    Param.Value = CType(parmBuilder, ParameterBuilder).Value
                    cmd.Parameters.Add(Param)
                Next
            End If
        Catch ex As DbException
            Throw New Exception("DB Exception ", ex)
        Catch exx As Exception
            Throw New Exception("PrepareCommand : ", exx)
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="connString"></param>
    ''' <param name="cmdType"></param>
    ''' <param name="cmdText"></param>
    ''' <param name="cmdParms"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ExecuteRow(ByVal connString As String, ByVal cmdType As CommandType, ByVal cmdText As String, Optional ByVal cmdParms As ParameterBuilder() = Nothing) As DataRow
        Dim oProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory(GetFactoryBySelection(_Factory))
        Dim Con As DbConnection = oProviderFactory.CreateConnection
        Con.ConnectionString = connString
        Dim cmd As DbCommand = Con.CreateCommand
        Dim oDataAdapter As DbDataAdapter = oProviderFactory.CreateDataAdapter
        Dim oDataRow As DataRow = Nothing
        Dim oDataTable As New DataTable
        Try
            PrepareCommand(cmd, Con, cmdType, cmdText, cmdParms)
            oDataAdapter.SelectCommand = cmd
            oDataAdapter.Fill(oDataTable)
            cmd.Parameters.Clear()
            If oDataTable.Rows.Count = 0 Then
                Return Nothing
            Else
                Dim oRow As DataRow = oDataTable.Rows(0)
                Return oRow
            End If
        Catch ex As DbException
            Throw New Exception("DB Exception ", ex)
        Catch exx As Exception
            Throw New Exception("ExecuteRow", exx)
        Finally
            Con.Close()
            Con.Dispose()
            Con = Nothing
            oDataTable.Dispose()
            oDataTable = Nothing
            cmd.Dispose()
            cmd = Nothing
            oDataAdapter.Dispose()
            oDataAdapter = Nothing
            oProviderFactory = Nothing
        End Try
    End Function
    ''' <summary>
    ''' FillSchema
    ''' </summary>
    ''' <param name="connString"></param>
    ''' <param name="cmdText"></param>
    ''' <param name="strTableName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function FillSchema(ByVal connString As String, ByVal cmdText As String, ByVal strTableName As String) As DataTable
        Dim oProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory(GetFactoryBySelection(_Factory))
        Dim conn As DbConnection = oProviderFactory.CreateConnection
        conn.ConnectionString = connString
        Dim oDataAdapter As DbDataAdapter = oProviderFactory.CreateDataAdapter
        Dim oCmdBuilder As DbCommandBuilder = oProviderFactory.CreateCommandBuilder
        Dim oDataTable As New DataTable
        Try
            If Not conn.State = ConnectionState.Open Then
                conn.Open()
            End If
            oDataAdapter.SelectCommand.CommandType = CommandType.Text
            oDataAdapter.SelectCommand.CommandText = cmdText
            oCmdBuilder.DataAdapter = oDataAdapter
            oDataAdapter.FillSchema(oDataTable, SchemaType.Source)
            oDataTable.TableName = strTableName
            Return oDataTable
        Catch exx As DbException
            Throw New Exception("DB Exception ", exx)
        Catch ex As Exception
            Throw New Exception("FillSchema", ex)
        Finally
            conn.Close()
            conn.Dispose()
            conn = Nothing
            oCmdBuilder.Dispose()
            oCmdBuilder = Nothing
            oDataTable.Dispose()
            oDataTable = Nothing
            oProviderFactory = Nothing
        End Try
    End Function
    ''' <summary>
    ''' ExcuteAdapter
    ''' </summary>
    ''' <param name="connString"></param>
    ''' <param name="oTable"></param>
    ''' <param name="cmdText"></param>
    ''' <param name="lngMaxID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ExcuteAdapter(ByVal connString As String, ByVal oTable As DataTable, ByVal cmdText As String, Optional ByRef lngMaxID As Long = 0) As Boolean
        Dim oProviderFactory As DbProviderFactory = DbProviderFactories.GetFactory(GetFactoryBySelection(_Factory))
        Dim conn As DbConnection = oProviderFactory.CreateConnection
        conn.ConnectionString = connString
        Dim oDataAdapter As DbDataAdapter = oProviderFactory.CreateDataAdapter
        Dim oCmdBuilder As DbCommandBuilder = oProviderFactory.CreateCommandBuilder
        Dim oSqlCmd As DbCommand = oProviderFactory.CreateCommand
        Dim trans As DbTransaction = Nothing
        Try
            If Not conn.State = ConnectionState.Open Then
                conn.Open()
            End If
            trans = conn.BeginTransaction
            oSqlCmd.Transaction = trans
            oSqlCmd.Connection = conn
            oSqlCmd.CommandText = cmdText
            oSqlCmd.CommandType = CommandType.Text
            oDataAdapter.SelectCommand = oSqlCmd
            oCmdBuilder.DataAdapter = oDataAdapter
            oCmdBuilder.GetUpdateCommand()
            oCmdBuilder.GetInsertCommand()
            oCmdBuilder.GetDeleteCommand()
            oDataAdapter.Update(oTable)
            '  oDataAdapter.SelectCommand = New SqlCommand("SELECT @IDENTITY", conn)
            trans.Commit()
            '  lngMaxID = CType(oDataAdapter.SelectCommand.ExecuteScalar(), Long)
        Catch ex As DbException
            trans.Rollback()
            Throw New Exception("DB Exception ", ex)
        Catch exx As Exception
            trans.Rollback()
            Throw New Exception("ExeculateAdapter", exx)
        Finally
            If conn.State = ConnectionState.Open Then conn.Close()
            conn.Dispose()
            conn = Nothing
            oSqlCmd.Dispose()
            oSqlCmd = Nothing
            oDataAdapter.Dispose()
            oDataAdapter = Nothing
            oCmdBuilder.Dispose()
            oCmdBuilder = Nothing
            oProviderFactory = Nothing
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="TableName"></param>
    ''' <param name="ColumnName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetColumnMaxValue(ByVal TableName As String, ByVal ColumnName As String) As Integer
        Try
            Dim SQL As String = "SELECT MAX(" & ColumnName & ")" & "AS " & ColumnName & " FROM " & TableName
            Dim oDataRow As DataRow = ExecuteRow(CONSTRING, CommandType.Text, SQL)
            If IsDBNull(ColumnName) = False Then
                Return Convert.ToInt32(oDataRow(ColumnName))
            Else
                Return 0
            End If
        Catch ex As DbException
            Throw New Exception("DB Exception ", ex)
        Catch exx As Exception
            Throw New Exception("GetColumnMaxValue", exx)
        Finally
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="TableName"></param>
    ''' <param name="ColumnName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetColumnCount(ByVal TableName As String, ByVal ColumnName As String) As Integer
        Try
            Dim SQL As String = "SELECT Count(" & ColumnName & ")" & "AS " & ColumnName & " FROM " & TableName
            Dim oDataRow As DataRow = ExecuteRow(CONSTRING, CommandType.Text, SQL)
            If IsDBNull(ColumnName) = False Then
                Return Convert.ToInt32(oDataRow(ColumnName))
            Else
                Return 0
            End If
        Catch ex As DbException
            Throw New Exception("DB Exception ", ex)
        Catch exx As Exception
            Throw New Exception("GetColumnCount", exx)
        Finally
        End Try
    End Function
End Class
Public Class ParameterBuilder
    Private _ParamName As String
    Private _Value As Object
    Private _DbType As DbType = Data.DbType.String
    Private _Direction As ParameterDirection = ParameterDirection.Input
    Private _Size As Integer = 0
    Private _SourceColumn As String = String.Empty
    Private _SourceVersion As DataRowVersion = DataRowVersion.Current
    Private _SourceColumnNullMapping As Boolean = False
    ''' <summary>
    ''' Initializes a new instance of the ParameterBuilder class.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
    End Sub
    ''' <summary>
    ''' Initializes a new instance of the ParameterBuilder class.
    ''' </summary>
    ''' <param name="ParameterName">Sets the name of the ParameterName.</param>
    ''' <param name="dbType">Sets the DbType of the parameter.</param>
    ''' <param name="Size">Sets the maximum size, in bytes, of the data within the column.</param>
    ''' <param name="Direction">Sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter.</param>
    ''' <param name="IsNullable">Sets a value that indicates whether the parameter accepts null values.</param>
    ''' <param name="SourceColumn">Sets the name of the source column mapped to the DataSet and used for loading or returning the Value.</param>
    ''' <param name="SourceVersion">Sets the DataRowVersion to use when you load Value.</param>
    ''' <param name="Value">Sets the value of the parameter.</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal ParameterName As String, ByVal dbType As DbType, ByVal Size As Integer, ByVal Direction As ParameterDirection, ByVal IsNullable As Boolean, ByVal SourceColumn As String, ByVal SourceVersion As DataRowVersion, ByVal Value As Object)
        Me._ParamName = ParameterName
        Me._DbType = dbType
        Me._Size = Size
        Me._Direction = Direction
        Me._SourceColumnNullMapping = IsNullable
        Me._SourceColumn = SourceColumn
        Me._SourceVersion = SourceVersion
        Me._Value = Value
    End Sub
    ''' <summary>
    ''' Initializes a new instance of the ParameterBuilder class.
    ''' </summary>
    ''' <param name="ParameterName">Sets the name of the ParameterName.</param>
    ''' <param name="dbType">Sets the DbType of the parameter.</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal ParameterName As String, ByVal dbType As DbType)
        Me._ParamName = ParameterName
        Me._DbType = dbType
    End Sub
    ''' <summary>
    ''' Initializes a new instance of the ParameterBuilder class.
    ''' </summary>
    ''' <param name="ParameterName">Sets the name of the ParameterName.</param>
    ''' <param name="Value">Sets the value of the parameter.</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal ParameterName As String, ByVal Value As Object)
        Me._ParamName = ParameterName
        Me._Value = Value
    End Sub
    ''' <summary>
    ''' Initializes a new instance of the ParameterBuilder class.
    ''' </summary>
    ''' <param name="ParameterName">Sets the name of the ParameterName.</param>
    ''' <param name="dbType">Sets the DbType of the parameter.</param>
    ''' <param name="Size">Sets the maximum size, in bytes, of the data within the column.</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal ParameterName As String, ByVal dbType As DbType, ByVal Size As Integer)
        Me._ParamName = ParameterName
        Me._DbType = dbType
        Me._Size = Size
    End Sub
    ''' <summary>
    ''' Initializes a new instance of the ParameterBuilder class.
    ''' </summary>
    ''' <param name="ParameterName">Sets the name of the ParameterName.</param>
    ''' <param name="dbType">Sets the DbType of the parameter.</param>
    ''' <param name="Size">Sets the maximum size, in bytes, of the data within the column.</param>
    ''' <param name="SourceColumn">Sets the name of the source column mapped to the DataSet and used for loading or returning the Value.</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal ParameterName As String, ByVal dbType As DbType, ByVal Size As Integer, ByVal SourceColumn As String)
        Me._ParamName = ParameterName
        Me._DbType = dbType
        Me._Size = Size
        Me._SourceColumn = SourceColumn
    End Sub
    ''' <summary>
    ''' Gets the name of the ParameterName.
    ''' </summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks></remarks>
    Public Property ParamName() As String
        Get
            Return Me._ParamName
        End Get
        Set(ByVal value As String)
            Me._ParamName = value
        End Set
    End Property
    ''' <summary>
    ''' Gets the value of the parameter.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Object</returns>
    ''' <remarks></remarks>
    Public Property Value() As Object
        Get
            Return _Value
        End Get
        Set(ByVal value As Object)
            _Value = value
        End Set
    End Property
    ''' <summary>
    ''' Gets the DbType of the parameter.
    ''' </summary>
    ''' <value></value>
    ''' <returns>DbType</returns>
    ''' <remarks></remarks>
    Public Property DbType() As DbType
        Get
            Return _DbType
        End Get
        Set(ByVal value As DbType)
            _DbType = value
        End Set
    End Property
    ''' <summary>
    ''' Gets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter.
    ''' </summary>
    ''' <value></value>
    ''' <returns>ParameterDirection</returns>
    ''' <remarks></remarks>
    Public Property Direction() As ParameterDirection
        Get
            Return _Direction
        End Get
        Set(ByVal value As ParameterDirection)
            _Direction = value
        End Set
    End Property
    ''' <summary>
    ''' Gets the maximum size, in bytes, of the data within the column.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Integer</returns>
    ''' <remarks></remarks>
    Public Property Size() As Integer
        Get
            Return Me._Size
        End Get
        Set(ByVal value As Integer)
            Me._Size = value
        End Set
    End Property
    ''' <summary>
    ''' Gets the name of the source column mapped to the DataSet and used for loading or returning the Value.
    ''' </summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks></remarks>
    Public Property SourceColumn() As String
        Get
            Return _SourceColumn
        End Get
        Set(ByVal value As String)
            _SourceColumn = value
        End Set
    End Property
    ''' <summary>
    ''' Sets the DataRowVersion to use when you load Value.
    ''' </summary>
    ''' <value></value>
    ''' <returns>DataRowVersion</returns>
    ''' <remarks></remarks>
    Public Property SourceVersion() As DataRowVersion
        Get
            Return _SourceVersion
        End Get
        Set(ByVal value As DataRowVersion)
            _SourceVersion = value
        End Set
    End Property
    ''' <summary>
    ''' Gets a value that indicates whether the parameter accepts null values.
    ''' </summary>
    ''' <value></value>
    ''' <returns>Boolean</returns>
    ''' <remarks></remarks>
    Public Property SourceColumnNullMapping() As Boolean
        Get
            Return _SourceColumnNullMapping
        End Get
        Set(ByVal value As Boolean)
            _SourceColumnNullMapping = value
        End Set
    End Property
End Class
Public Enum GetFactory
    Odbc = 1
    OleDb = 2
    SqlClient = 3
End Enum

Sample Usage of ClsDbConnection

'Insert or Update Record
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    Try
        Dim param(8) As ParameterBuilder
        param(0) = New ParameterBuilder("@proj_no", DbType.String)
        param(0).Value = tbProjectNo.Text
        param(1) = New ParameterBuilder("@request_hrs", DbType.Int16)
        param(1).Value = Val(tbEstimatedHrs.Text)
        param(2) = New ParameterBuilder("@design", DbType.String)
        param(2).Value = cbStatus.Text
        param(3) = New ParameterBuilder("@assign_id", DbType.String)
        param(3).Value = gUserID
        param(4) = New ParameterBuilder("@assign_by", DbType.String)
        param(4).Value = cbConfirmedBy.Text
        param(5) = New ParameterBuilder("@date_request", DbType.DateTime)
        param(5).Value = Format(Convert.ToDateTime(dDateServer, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat), "yyyy-MM-dd hh:mm:ss tt")
        param(6) = New ParameterBuilder("@work_desc", DbType.String)
        param(6).Value = tbRemarks.Text
        param(7) = New ParameterBuilder("@new_task", DbType.Boolean)
        param(7).Value = iNewTask
        param(8) = New ParameterBuilder("@tag_id", DbType.Int16)
        param(8).Value = Val(gCurrentTask)

        Dim SQL As String

        If btnSave.Text = "&Submit" Then
            SQL = "INSERT INTO project_information_task_request(proj_no, request_hrs, design, assign_id, assign_by, date_request,work_desc,new_task,tag_id) " & _
                  "VALUES('" & param(0).Value & "'," & param(1).Value & ",'" & _
                  param(2).Value & "','" & param(3).Value & "','" & param(4).Value & "','" & _
                  param(5).Value & "','" & param(6).Value & "'," & param(7).Value & "," & param(8).Value & ")"
        Else
            SQL = "UPDATE project_information_task_request SET proj_no = '" & param(0).Value & "', request_hrs = " & param(1).Value & _
                  ", design = '" & param(2).Value & "', assign_id = '" & param(3).Value & _
                  "', assign_by = '" & param(4).Value & "', date_request = '" & param(5).Value & _
                  "', work_desc = '" & param(6).Value & _
                  "' WHERE task_id=" & gProject_ID
        End If

        clsDbConnection.ExecuteNonQuery(clsDbConnection.CONSTRING, CommandType.Text, SQL, param)

        If btnSave.Text = "&Submit" Then
            MessageBox.Show("Submit Successfully.", "Request Task", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show("Update Successfully.", "Request Task", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        Me.Close()
    Catch ex As Exception
        MessageBox.Show(ex.ToString)
    End Try
End Sub
 
'Retrieve data from Database
Private Sub LoadProjects(byval Project as Integer)
    Dim sQuery As String

    sQuery = "SELECT proj_no, proj_name AS projects FROM project_information WHERE proj_tag=Project ORDER BY proj_name"
 
    Try
        Dim oTable As DataTable = clsDbConnection.ExecuteTable(clsDbConnection.CONSTRING, CommandType.Text, sQuery)
            
        If oTable.Rows.Count > 0 Then
            Dim reader As New DataTableReader(oTable)
                
            Do While reader.Read
                //Get the Field Value
                messagebox.show(reader("proj_no").ToString & " - " & reader("proj_name").ToString)					
            Loop
            reader.Close()
            reader = Nothing
        End If
        oTable.Dispose()
    Catch ex As Exception
        MessageBox.Show(ex.ToString)
    End Try
End Sub