VB.NET and Microsoft Access: Old table entries stu

2019-09-12 09:05发布

问题:

I'm having a very strange issue with retrieving and displaying the contents of an Access table in a DataGridView. The problem is as follows:

I'm working on an application in VS2010 that has two forms. The main form displays the second form upon a button press, and the second form contains a DataGridView that is linked to an Access table on my local PC using a BindingSource (or DataSet, or what have you). When I first set the Data Source property of my grid to the table as a new data source (meaning I add it to the project right then and there), the grid accurately reflects the current contents of my table. After that point, however, I am completely unable to change the displayed contents of the table on the grid; the contents are stuck as those rows. Even after both adding and removing rows through both the program I'm writing and through Access itself, the grid's contents never change to reflect the current data. The ghost contents also persist through program resets (closing the program and re-opening) and through reassignment of the data source.

The most progress I've made is being able to clear the grid completely using

grdTableDisplay.DataSource = Nothing
grdTableDisplay.Rows.Clear()

But on reassignment of the Data Source using

grdTableDisplay.DataSource = TableDisplayBindingSource

the ghost data returns. This leads me to believe that my binding source or data set aren't being updated at all after the initial data source setup.

I would greatly appreciate any insight into this issue that anyone can offer me; this problem is preventing me from testing my application and is probably quite simple to resolve. Thanks in advance!

回答1:

It turns out that I was able to resolve this after digging around MSDN for a while more. When I set up the connection for my grid's data source, it sends you through a wizard that helps you set up things like the type of data (database) and the connection string, among other things. After proceeding past the connection string stage, a pop up window asks you if you'd like to store a local copy of the database file that will be automatically updated by some event or another. SAY NO!!! This file isn't updated at all, and VS2010 helpfully redirects your data source to the local copy, which is never updated, which results in old, useless data in your grids. After redoing the connection and not saving a local database copy, my grid finally reflects the current contents of my table. I hope this saves somebody the headache of looking for the equivalent of a light switch for a room that is actually located outside of the room!