Imports System Imports System.Configuration Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlTypes Namespace TKB.VV.DB Public Enum LLBLError AllOk ' // Add more here (check the comma's!) End Enum Public Interface ICommonDBAccess Function Insert() As Boolean Function Update() As Boolean Function Delete() As Boolean Function SelectOne() As DataTable Function SelectAll() As DataTable End Interface Public MustInherit Class clsDBInteractionBase Implements IDisposable Implements ICommonDBAccess #Region " Class Member Declarations " Protected m_scoMainConnection As SqlConnection Protected m_iRowsAffected As Integer Protected m_iErrorCode As SqlInt32 Protected m_bMainConnectionIsCreatedLocal As Boolean Protected m_cpMainConnectionProvider As clsConnectionProvider Private m_sConnectionString As String Private m_bIsDisposed As Boolean #End Region Public Sub New() ' // Initialize the class' members. InitClass() End Sub Private Sub InitClass() ' // create all the objects and initialize other members. m_scoMainConnection = new SqlConnection() m_bMainConnectionIsCreatedLocal = True m_cpMainConnectionProvider = Nothing m_iErrorCode = New SqlInt32(LLBLError.AllOk) m_bIsDisposed = False End Sub Overloads Public Sub Dispose() Implements IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Overridable Overloads Protected Sub Dispose(ByVal bIsDisposing As Boolean) ' // Check to see if Dispose has already been called. If Not m_bIsDisposed Then If bIsDisposing Then ' // Dispose managed resources. If m_bMainConnectionIsCreatedLocal Then ' // Object is created in this class, so destroy it here. m_scoMainConnection.Close() m_scoMainConnection.Dispose() m_bMainConnectionIsCreatedLocal = True End If m_cpMainConnectionProvider = Nothing m_scoMainConnection = Nothing End If End If m_bIsDisposed = True End Sub Public Overridable Function Insert() As Boolean Implements ICommonDBAccess.Insert ' // No implementation, throw exception Throw New NotImplementedException() End Function Public Overridable Function Delete() As Boolean Implements ICommonDBAccess.Delete ' // No implementation, throw exception Throw New NotImplementedException() End Function Public Overridable Function Update() As Boolean Implements ICommonDBAccess.Update ' // No implementation, throw exception Throw New NotImplementedException() End Function Public Overridable Function SelectOne() As DataTable Implements ICommonDBAccess.SelectOne ' // No implementation, throw exception Throw New NotImplementedException() End Function Public Overridable Function SelectAll() As DataTable Implements ICommonDBAccess.SelectAll ' // No implementation, throw exception Throw New NotImplementedException() End Function #Region " Class Property Declarations " Public WriteOnly Property cpMainConnectionProvider() As clsConnectionProvider Set(ByVal Value As clsConnectionProvider) If Value Is Nothing Then ' // Invalid value Throw New ArgumentNullException("cpMainConnectionProvider", "Nothing passed as value to this property which is not allowed.") End If ' // A connection provider object is passed to this class. ' // Retrieve the SqlConnection object, if present and create a ' // reference to it. If there is already a MainConnection object ' // referenced by the membervar, destroy that one or simply ' // remove the reference, based on the flag. If Not (m_scoMainConnection Is Nothing) Then ' // First get rid of current connection object. Caller is responsible If m_bMainConnectionIsCreatedLocal Then ' // Is local created object, close it and dispose it. m_scoMainConnection.Close() m_scoMainConnection.Dispose() End If ' // Remove reference. m_scoMainConnection = Nothing End If m_cpMainConnectionProvider = CType(Value, clsConnectionProvider) m_scoMainConnection = m_cpMainConnectionProvider.scoDBConnection m_bMainConnectionIsCreatedLocal = False End Set End Property Public ReadOnly Property iErrorCode() As SqlInt32 Get Return m_iErrorCode End Get End Property Public Property sConnectionString() As String Get Return m_sConnectionString End Get Set (ByVal Value As String) m_sConnectionString = Value m_scoMainConnection.ConnectionString = m_sConnectionString End Set End Property Public Readonly Property iRowsAffected() As Integer Get Return m_iRowsAffected End Get End Property #End Region End Class End Namespace