I initially populate data on the main form with a Using block which by definition closes the connection. See the using block below. When I return to the main form from the edit form I perform an almost identical using block (except that the command objects CommandText property is already set and I don't change them). I don't know how I can close the connection as you suggest any more than I have closed it. Do you have any further advice?.
Thanks,
Code:
sCnxn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sCurrentPath & "\"
& sDBFileName & ";User ID=admin;Password=;"
Try
oDataSet = New DataSet
Using oCnxn As New OleDbConnection(sCnxn)
oCnxn.Open()
cmdAirports.CommandText = "SELECT * FROM Airports"
cmdAirports.Connection = oCnxn
daAirports.SelectCommand = cmdAirports
daAirports.Fill(oDataSet, "Airports")
cmdRISource.CommandText = "SELECT * FROM RISource"
cmdRISource.Connection = oCnxn
daRISource.SelectCommand = cmdRISource
daRISource.Fill(oDataSet, "RISource")
cmdROSource.CommandText = "SELECT * FROM ROSource"
cmdROSource.Connection = oCnxn
daROSource.SelectCommand = cmdROSource
daROSource.Fill(oDataSet, "ROSource")
End Using
Catch ex As Exception
'TODO - add handling for database error
End Try
Bookmarks