Search code examples
c#ms-accessdatasettableadapterstrongly-typed-dataset

TableAdapter Fill doesn't update database


I want to insert data into MS Access using a DataSet and TableAdapters, but unfortunately it doesn't update the table in MS Access when I run this code:

DataSet2TableAdapters.Tabelle1TableAdapter tabelle1TableAdapter = new DataSet2TableAdapters.Tabelle1TableAdapter();

DataSet2 dataSet2 = new DataSet2();
dataSet2.Tabelle1.Insert("hallo", 1);
tabelle1TableAdapter.Update(dataSet2.Tabelle1);

This is just a test file in my actual MS Access file the table has a lot of columns so I really like to use the "Insert" method or something similiar because it's easy to write.

Some suggestions how I can accomplish this?


Solution

  • One common pitfall in this situation is that your database file may get overwritten in your compile/execute cycle. Everything you added in one execution may get lost next time you compile your project, with the database file being reset to its initial state. VS stores the original DB file in your project root folder. Your application uses its own copy stored in the bin folder (or somewhere else).

    There's a few troubleshooting steps you can take in order to establish if this is actually your problem and eventually solve it: 1) in the solution explorer window, right-click your database and select Properties. Change Copy to Output Directory to Do not copy. 2) After compiling your application, run it a couple of times outside VS and the debugging environment and verify if the problem goes away. 3) Modify your existing code to reload your data, from the database, right after an insertion or deletion has been successfully executed and verify if the problem goes away.

    Or, if you know exactly where the file is located, simply verify that the records were actually properly stored.