Emman
Emman

Reputation: 105

Save data permanently in database

Guys I have a problem in saving data in my database.
The system I am developing saves data in the database and displays the data in the datagrid and that runs smoothly, but the problem is whenever I restart or reboot the application the data disappears and the database was again empty but the data entered directly in the database using show table data, didn't disappear.
Am I missing something in my program?

Upvotes: 3

Views: 2840

Answers (3)

Khalid J. Abualrob
Khalid J. Abualrob

Reputation: 41

Do the following steps:

  1. Right click on your Database.mdf or Database.accdb database file from solution explorer
  2. Click on properties
  3. Select 'Do Not Copy' from COPY TO OUTPUT DIRECTORY drop down list
  4. Remember to close your database if it was opened on access

Upvotes: 4

Mahdi Tahsildari
Mahdi Tahsildari

Reputation: 13582

I had the same problem long time ago. I remember that the data that I would enter in a execution would vanish on the next execution and it was because the local database file was copied (and hence overwritten) on each execution.

I solved it by setting Copy to Output Directory property of my local database to Do not copy I suppose, test it, if it's not Do not Copy then it may be Copy Always.

But I'm sure my (same) problem solved this way.
Hope it works in your case too.

EDIT: Eman, do the following steps. It should solve your problem.

1.right click on your abc.mdf database file from solution explorer
2.hit properties
3.change COPY TO OUTPUT DIRECTORY
4.run your application, add a row, exit app, run it again
5.if row is lost, goto step 1, else exit

Upvotes: 2

alpha
alpha

Reputation: 17

try using sql server database. write the code in form_load().

Upvotes: -1

Related Questions