Saving data back to a database

Hi all,

Im having trouble saving changes i have made to data in one of my databases.

Basically i have a form that loads data from my database into a dataset using a tableadapter. You can then make changes to the data using the tableadapter.update method etc. I can see that these changes are occuring on my form using a listbox and a datagridview, but when i stop debugging and load the form again no changes are kept!

I can see that other people have had the same problem and some resolved them by modifying the data connection to reference the database in the bin/debug directory. However this doesn't seem to be working for me. I tried modifying the connection after i had completed my project as thats when i found out i had to. Do you have to start the project again and modify the connection at the start before you code anything

I really dont know whats going on with this.. it should be easy to save your changes. The main section of my code is listed below.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

BindingSource1.EndEdit()

Try

PeopleTableTableAdapter1.Update(Me.PeopleDataSet.PeopleTable)

Catch ex As Exception

MessageBox.Show("Update Failed")

End Try

Call RefreshDataset()

End Sub

Private Sub RefreshDataset()

Me.PeopleTableTableAdapter1.Fill(Me.PeopleDataSet.PeopleTable)

End Sub

I would be extremely grateful if someone could help me out.

Cheers,

Aaron



Answer this question

Saving data back to a database

  • Eddie Li - MSFT

    Hi Aaron,

    I had the same problem (or misunderstanding). All you need to do is go to solution explorer, select your database and then in the properties:

    set 'copy to output directory' to 'copy if newer'.

    Your data in your bin/debug or release is being replaced by old data at each start of your application.

    Hope this helps.

    Arnie

    Tucson, AZ


  • Chris Conti

    Thanks Arnie... works like a charm now. You're a legend!


  • Saving data back to a database