Do they really? You haven't actually showed us any of these attempts or told us what actually happens so we have no idea whether you're accurately reflecting what's actually happening. Here's what should be happening:
- Call
Fill
on a data adapter to populate a DataTable
.
- Bind that
DataTable
to a BindingSource
and that to the grid.
- Edit the data via the UI as required.
- Call
Validate
on the form and EndEdit
on the BindingSource
to ensure all changes have been committed to the DataTable
.
- Call
Update
on the data adapter to save the changes from the DataTable
to the database.
That's it, that's all. On step 5, there are three possible outcomes:
- The call succeeds and returns zero. This means that there were no changes to save.
- The call succeeds and returns a non-zero value. This means that there were changes to save and they were saved.
- The call fails and throws an exception. This means that something went wrong and the exception will tell you what it was.
That is the first thing to check. If there's no exception and the return value is not zero, everything is working exactly as it should be and you are trying to solve the wrong problem.
As suggested above, a very common problem with beginners using Access databases or any other file-based database is that, by default, the working database gets overwritten every time they make a code change and run the project again. If you save some data changes, exit the app and then run the project again immediately, are those changes still there? The project is not built again if there are no code changes so the working database is not overwritten. If you make a code change - even just add a space and then delete it - and run the project, are the changes gone? In that case, it is definitely the case that your working database is being overwritten.
Here's how it works. When you add a data file to your project, it becomes a source file, like your code files. That data file should be kept clean, so it is ready to be deployed with the final app. It should contain the schema and any default data but you should not be polluting it with test data. For that reason, when you build, VS copies that data file into the program folder along with your EXE and it is that copy that you access at run time. When you create a Release build to deploy, instead of a Debug build to test, you will get a nice clean copy of the database to deploy.
The problem is that, by default, the source data file is copied over the working data file every time you build your project. This is not what most people want. Select the data file in the Solution Explorer and open the Properties window. The value of the
Copy to Output Directory
property will be
Copy Always
by default. You should change that to
Copy if Newer
, which means that the working database will only be overwritten if the source file is newer than the working file. That will generally only happen when you make changes to the source file - when you change the schema or the default data - in which case you would not want to keep working with the old copy anyway. Now, you can test as much as you want and your changes will be kept between runs. Just be aware that, if you open the source file outside of VS, this might update its Last Modified Date and trigger a copy on the next build, even if you don't change the contents of the file. If you ever want to refresh your working database without making a code change, simply delete the working file from the bin folder and force a rebuild of the project.