Changes to Access database do not persist when run

2019-01-03 07:03发布

I am creating a library application in Visual Studio 2010 Professional and Access 2010. I bind the Access database to Visual Studio. When I fill out the fields and click submit I can see the new record in the DataGridView, but when I close the application the new record is not saved and I have to input the record again.

Can somebody help me to know why when I input the new record through the application the record is not saved in the database?

1条回答
仙女界的扛把子
2楼-- · 2019-01-03 07:55

It is a very common situation. You have your database file (the MDB or ACCDB file) listed between your project items. If you click on this file and look at the properties window you will see a property called Copy to the output directory. If this property is set to Copy Always then every time you start a debug session the database file listed in your project items is copied by VS in the output directory (usually BIN\DEBUG). Of course this copy doesn't contain the records inserted in your last debug session and you think that your previous insert has failed.

Setting this property to Copy If Newer, the mentioned behavior will happen only if you change the database schema manually.

Setting this property to Copy Never, will let you manually copy the database file.

查看更多
登录 后发表回答