Thanks for your patience. Here's the appropriate snippets (I believe this
will have the full necessary code).
Since it's not shown, and maybe it make a difference, frmImport is opened
from frmMain using ShowDialog (hence why the return value is set).
-----------------------------------------------------------------------------------------------------------
Public Class frmImport
Private WithEvents oImp As Importer_ADOCE
Private Sub cmdImport_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdImport.Click
Me.lblInstructions.Enabled = False
Me.txtFileLocation.Enabled = False
Me.cmdOpen.Enabled = False
Me.lblDivider.Visible = True
Me.StatusLabel.Visible = True
Me.lblStatus.Visible = True
Me.prgbrStatus.Visible = True
Me.Refresh()
'begin the import with the path
Dim oImp As Importer_ADOCE
oImp = New Importer_ADOCE(txtFileLocation.Text)
If oImp.Import = True Then
'close the form and refresh the tree
MessageBox.Show("Import Successfull")
Me.DialogResult = Windows.Forms.DialogResult.OK
Me.Close()
End If
End Sub
Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOpen.Click
Me.OpenFileDialog1.Filter = "BRED database (*.cdb)|*.cdb"
If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.txtFileLocation.Text = Me.OpenFileDialog1.FileName
Me.cmdImport.Enabled = True
End If
End Sub
Private Sub oImp_ImportingTable(ByVal TableName As String) Handles
oImp.ImportingTable
Me.lblStatus.Text = "Importing " & TableName
Me.Refresh()
End Sub
End Class
-----------------------------------------------------------------------------------------------------
Imports InTheHand.Data.Adoce
Public Class Importer_ADOCE
Inherits Importer
''' <summary>
''' Raised by the inheriting class when starting to import a new table
''' </summary>
''' <param name="TableName"></param>
''' <remarks></remarks>
Public Event ImportingTable(ByVal TableName As String)
Private strFile As String
Private cnADOCE As AdoceConnection
Sub New(ByVal SourceFile As String)
strFile = SourceFile
End Sub
Public Function Import() As Boolean
'open the connection to the source and transfer each table
Try
cnADOCE = New AdoceConnection(strFile)
cnADOCE.Open()
SendTable("Organization")
SendTable("Group")
SendTable("Hierarchy")
SendTable("Facility")
SendTable("Group_Facilities")
SendTable("Sample_Location")
SendTable("Building")
SendTable("Building_System")
SendTable("System_Component")
SendTable("Section")
SendTable("SectionDetails")
SendTable("Inspection_Data")
'SendTable("Sample_Data")
'SendTable("Sample_Subcomponent")
'SendTable("Sample_Subcomp_Distress")
Return True
Catch ex As Exception
Return False
Finally
If Not cnADOCE Is Nothing Then
If cnADOCE.State <> Data.ConnectionState.Closed Then
cnADOCE.Close()
End If
cnADOCE.Dispose()
End If
End Try
End Function
Public Sub SendTable(ByVal TableName As String)
Dim dr As AdoceDataReader
Try
RaiseEvent ImportingTable(TableName)
dr = New AdoceCommand("SELECT * FROM " & TableName, cnADOCE).ExecuteReader()
MyBase.TransferTable(TableName, dr)
Finally
If Not dr Is Nothing Then
If Not dr.IsClosed Then
dr.Close()
End If
dr.Dispose()
End If
End Try
End Sub
End Class
------------------------------------------------------------------------------------------------------------------------------------------------------------
Public MustInherit Class Importer
Private dsBRED As New Data.DataSet
''' <summary>
''' Copy the source table to the BRED database
''' </summary>
''' <param name="TableName"></param>
''' <param name="SourceReader"></param>
''' <remarks></remarks>
Protected Sub TransferTable(ByVal TableName As String, ByVal SourceReader As
Data.IDataReader)
Dim da As Data.SqlServerCe.SqlCeDataAdapter
Dim dc As Data.SqlServerCe.SqlCeCommand
Dim cb As Data.SqlServerCe.SqlCeCommandBuilder
Dim nr As Data.DataRow
Try
'erase the existing table data
dc = New Data.SqlServerCe.SqlCeCommand("DELETE FROM " & TableName,
Connection)
dc.ExecuteNonQuery()
'now fill
da = New Data.SqlServerCe.SqlCeDataAdapter("SELECT * FROM " & TableName,
Connection)
cb = New Data.SqlServerCe.SqlCeCommandBuilder(da)
da.Fill(dsBRED, TableName)
Do While SourceReader.Read
nr = dsBRED.Tables(TableName).NewRow()
For i As Integer = 0 To dsBRED.Tables(TableName).Columns.Count - 1
nr.Item(i) = SourceReader.Item(i)
Next
dsBRED.Tables(TableName).Rows.Add(nr)
'this will keep the number of rows in the dataset low,
'therefore keeping the memory low
If dsBRED.Tables(TableName).Rows.Count > 100 Then
da.Update(dsBRED.Tables(TableName))
dsBRED.Tables(TableName).Rows.Clear()
End If
Loop
da.Update(dsBRED.Tables(TableName))
'remove the table to save memory
dsBRED.Tables.Remove(TableName)
Catch ex As Exception
End Try
End Sub
End Class