I have created a database in ms access and a form, in which i want to add some records, it is updating correctly, but when i close the form and restart the application and started to add new records the previous records are deleted automatically. please help me in this

Dani AI

Generated

A common cause of "records save but disappear after restart" with Access + VB projects is the project database file being overwritten by the build output. asked for the code and flagged DataSet behavior — both points are useful. The checklist below will quickly narrow the real cause (file-copy vs save logic vs startup code).

First, confirm which .mdb/.accdb file the app actually opens at runtime. Log the connection string to the debug output:

Debug.WriteLine(conn.ConnectionString)

Open that exact file in MS Access after adding records. If the file under bin\Debug (or bin\Release) contains the new rows but the original project file does not, the solution is to stop Visual Studio from overwriting it (select the DB in Solution Explorer → Properties → "Copy to Output Directory": set to "Copy if newer" or "Do not copy"), or move the DB to a permanent, writable location (ProgramData or AppData) and use an absolute path in the connection string.

Other causes to check: in-memory DataSet changes not propagated (ensure the DataAdapter/TableAdapter Update runs and that Insert/Update/Delete commands exist — OleDbCommandBuilder can auto-generate simple commands), transaction code that never commits, or startup code that truncates/recreates tables. Also verify the connection string isn’t pointing at a different file via a relative path or |DataDirectory| token, and confirm the app has write permission and the file isn’t held open exclusively by Access.

Quick checklist: (1) Log and inspect the runtime DB file; (2) Stop project file-copying or relocate the DB; (3) Verify persistence code calls Update/commit; (4) Search for any startup SQL that clears data; (5) Use an absolute, writable DB path. These steps normally reveal and fix the issue.

Recommended Answers

All 2 Replies

Show your code.. You checked the DB when you close the application? Once saved in Db will not delete automatically Either your deleting in your code or you are not loading it back.

How are you retrieving and storing your data? Dataset? If so are you remembering that the dataset is not connected to the Database once populated? i.e. you can insert/ modify/ Delete records in it's datatables (they're held in memory) but you have to make specific calls to update the Database with the dataset data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.