Imports System.Data
Imports System.Data.OleDb
Public Class mdbConnectClass
Private mCn As OleDbConnection
Private mDataSet As New DataSet("Microsoft.Jet.OleDb.4.0")
Public Sub New(ByVal stMdbPath As String)
Dim stCn As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & stMdbPath
mCn = New OleDbConnection(stCn)
mCn.Open()
End Sub
Public Function SqlToTable(ByVal stSQL As String, ByVal stTableName As String) As mdbClass
Return New mdbClass(mCn, mDataSet, stSQL, stTableName)
End Function
Public ReadOnly Property DataSet() As DataSet
Get
Return mDataSet
End Get
End Property
End Class
Public Class mdbClass
Private mDataAdapter As New OleDbDataAdapter
Private mBuilder As OleDbCommandBuilder
Private mDataView As DataView
Public Sub New(ByVal obCn As OleDbConnection, ByVal objDataSet As DataSet, ByVal stSQL As String, ByVal stName As String)
mDataAdapter.SelectCommand = New OleDbCommand(stSQL, obCn)
mBuilder = New OleDbCommandBuilder(mDataAdapter)
mDataAdapter.Fill(objDataSet, stName)
mDataView = New DataView(objDataSet.Tables(stName))
End Sub
Public ReadOnly Property DataTable() As DataTable
Get
Return mDataView.Table
End Get
End Property
Public ReadOnly Property DataView() As DataView
Get
Return mDataView
End Get
End Property
Public Sub Update()
mBuilder.GetUpdateCommand()
mDataAdapter.Update(mDataView.Table)
End Sub
End Class