none
Database loading and saving issue RRS feed

  • Question

  • Greetings.

    I have an application, reading and editing a database file. I imported a  database file (.accdb)  into my project and I employed its details (labels and textboxs) and datagridview into my form. Then I created 3 buttons to add, save and delete with below codes :

    Private Sub btnNew_Click(sender As Object, e As EventArgs) Handles btnNew.Click
            Table1BindingSource.AddNew()
        End Sub
    
        Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
            Try
    
                Table1BindingSource.EndEdit()
    
                Table1TableAdapter.Update(Database_productsDataSet.Table1)
                MsgBox("saved!")
            Catch ex As Exception
                MsgBox(ex.Message)
    
            End Try
    
    
    
        End Sub
    
        Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
            Table1BindingSource.RemoveCurrent()
        End Sub

    Everything works fine! When I add a new item in the table and save it , it actually saves the database file in hard drive, but when I run the program for the second time , every changes are gone!

    I figured out what's going on:

    When I  imported the database , I browsed the database file somewhere out of the project folder, but  I approved the messagebox which asks if you want VS 2013 to make a copy ... ).

    Now when I run my application and make some changes and save the changes, application updates the copy version of db file in its folder. Second time of running the application loads the original db file i first chose in importing. so all changes are gone and I still have the original content.

    How to solve the issue ?

    Thanks





    • Edited by Kevin993 Wednesday, February 21, 2018 12:46 PM
    Wednesday, February 21, 2018 12:42 PM

Answers

  • Hi Kevin993,

    You just change DataBase1's Copy to Output directory property to Copy if newer.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Kevin993 Friday, February 23, 2018 9:27 AM
    Friday, February 23, 2018 6:10 AM
    Moderator