Results 1 to 4 of 4

Thread: Update problem with deleted rows in VB

  1. #1
    Join Date
    Nov 2008
    Posts
    30

    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?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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...

  3. #3
    Join Date
    Nov 2008
    Posts
    30

    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

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    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?

Similar Threads

  1. Installing ipod update 5.0.1 deleted Backup
    By Honeykay in forum Portable Devices
    Replies: 4
    Last Post: 16-02-2012, 05:01 AM
  2. Replies: 4
    Last Post: 03-12-2010, 07:33 AM
  3. Deleted Messages can't be deleted from "Deleted Items"
    By NIcaBoy in forum Windows Vista Mail
    Replies: 2
    Last Post: 16-02-2010, 08:33 AM
  4. How to SQL Update trigger example Deleted
    By spuff in forum Software Development
    Replies: 3
    Last Post: 18-08-2009, 02:20 PM
  5. Replies: 2
    Last Post: 09-07-2009, 08:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,572,141.97534 seconds with 16 queries