Private Sub FileOpen()
Try
With OpenFileDialog
.FileName = ""
.AddExtension = True
.CheckFileExists = True
.CheckPathExists = True
'.InitialDirectory = My.Computer.FileSystem.GetParentPath(My.Settings.dbPath) /////Remarked out, just left in in case I want to reactivate it!
.Filter = "MHManager Database|*.mhm"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
My.Settings.dbPath = .FileName ' Not needed i just use settings to store the value if I want to use it later in another windows form.
'Open the Database
OpenDatabase(.FileName)
Exit Sub
End If
End With
Catch ex As Exception
'Display an error to the user.
MsgBox("CORRUPTED OR INVALID DATABASE!" & Chr(13) & Chr(13) & "An error occurred. Error Number: " & Err.Number & _
" Description: " & Err.Description & " Source: " & Err.Source, MsgBoxStyle.Critical, "ERROR!")
End Try
End Sub
Public Sub OpenDatabase(ByVal filename As String)
Dim strConnection As String
'Set the Connection String
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" _
& filename & "; Persist Security Info=False"
cn.ConnectionString = strConnection
'Open the Connection
cn.Open()
' Fill the Contacts DataTable
daContact.Fill(dsContact, "Contact")
dtContact = dsContact.Tables.Item("Contact")
' Fill the Package DataTable
daPackage.Fill(dsPackage, "Package")
dtPackage = dsPackage.Tables.Item("Package")
' Fill the Service Table
daService.Fill(dsService, "Service")
dtService = dsService.Tables.Item("Service")
'set Status of Database
My.Settings.dbOpened = True
'Close the Connection
cn.Close()