Update problem with deleted rows in VB
Using VB2005 Pro and an ACCESS2003 .mdb file
I have an application with the main form for displaying/browsing data. A second form is used to edit data. Each of these forms use their own datasets data adapters etc. After editing data in the editing form upon returning to the main browsing form I perform a .fill with each of the dataadapters to pull any changes made in the other form into the dataset on the main form. This works perfectly with changed values but when I delete a record on the edit form that record remains in the dataset on the first form even after I do the fill. If I close the app and restart it the deleted record is indeed gone. Each table in the dataset on the main form has a primarykey defined. Why don't deleted records in the source get removed from the dataset on the main form when I perform the fill?
Any ideas?
Re: Update problem with deleted rows in VB
Ah, I expect that you need to close the connection to flush the cache and reopen it to rerun the query. Note that the JET engine used to manage Access databases is a dead-end technology... It also caches changes and does not write to the database file until the connection is idle...
Re: Update problem with deleted rows in VB
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
Re: Update problem with deleted rows in VB
Yes, you're populating the DataTable objects, I can see that. But on the other form where the changes are made, are you closing the connection or
(perhaps better yet) using a transaction to force JET to write to the the database file?