0

I have been struggling with question for some time now and I have tried Everything. there are similar questions on stack overflow but I have tired all solutions none of them worked for me. The problem is changes are not stored on the data base file after I call the data source binding. below is the code snippet for save button

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

    If isValidData() = True Then ' sub routine that checks data inputted into textboxes is valid.
        Try
            ' i get data from the textboxes on form which are binded to the bindingsource viewplanet... 
            Me.ViewPlanetAlliancesBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.DsLab4)
            MessageBox.Show("Successfully Saved Data Row")
            Call updateViewPlanetAlliance()

        Catch ex As DBConcurrencyException
            MessageBox.Show("A concurrency erro occured. " & "the row was not deleted.", "Concurrency Exception")
            Me.ViewPlanetAlliancesTableAdapter.FillByRegionID(DsLab4.viewPlanetAlliances, CInt(Me.lstRegion.SelectedValue))

        Catch ex As ArgumentException
            MessageBox.Show(ex.Message, "Argument exception")
            Me.ViewPlanetAlliancesBindingSource.CancelEdit()
        Catch ex As DataException
                MessageBox.Show(ex.Message, ex.GetType.ToString)
                Me.ViewPlanetAlliancesBindingSource.CancelEdit()
            End Try

        Else
            Try
                Me.TableAdapterManager.UpdateAll(Me.DsLab4)
            Catch ex As DBConcurrencyException
                MessageBox.Show("A concurrency erro occured. " & "the row was not deleted.", "Concurrency Exception")
            Me.ViewPlanetAlliancesTableAdapter.FillByRegionID(DsLab4.viewPlanetAlliances, CInt(Me.lstRegion.SelectedValue))
        End Try

        End If

End Sub

This is what my form looks like and how my data is displayed

enter image description here

djv
  • 15,168
  • 7
  • 48
  • 72
  • Do you get an error? If so, then where is it being caused and what does it tell you? – A Friend Feb 24 '17 at 14:20
  • 2
    What database engine are you using? How are you checking to see if there is data in the database after you close your app? – Chris Dunaway Feb 24 '17 at 14:21
  • no I don't get any error in saving database. other than data validation which are resolved by isValid function – oopragmmer Feb 24 '17 at 14:22
  • Very likely duplicate of [Why saving changes to a database fails?](http://stackoverflow.com/q/17147249/1070452) – Ňɏssa Pøngjǣrdenlarp Feb 24 '17 at 14:24
  • I have added the form image of how i am taking the data from textboxes which are binded to the viewplanetbindingsource – oopragmmer Feb 24 '17 at 14:28
  • @Plutonix I have seen that question and I did made change suggested on that question of changing database file property to "copy only if newer" that did not fix my problem – oopragmmer Feb 24 '17 at 14:30
  • The way to tell if it updated is to use the return from the Update *function* not the absence of an exception. You still havent told us which DB this is, so that is about as much help as you can get short of WAGs – Ňɏssa Pøngjǣrdenlarp Feb 24 '17 at 14:36
  • I am using the local SQL database file. to see updated results i check the datagridview which is connected to the binding source – oopragmmer Feb 24 '17 at 14:40
  • You are better off verifying that the data has been written by looking at it, not using your application. For example, it it's sql server, use ssms. – Dan Bracuk Feb 24 '17 at 14:50
  • The way to tell if your code succeeds in adding/updating is to check the return from the Update functions. If it says it added/updated N rows, it did. If you cant see the added/changed row(s) in a DB Browser like SSMS (*not* your code), then you are looking at a different instance than the code is using. If it is there, but then gone the next time you run, see the link. – Ňɏssa Pøngjǣrdenlarp Feb 24 '17 at 15:02
  • 1
    Get away from the typed Data sets and Table adapters, they are buggy. Use pure SQL or Entity Framework, way more solid options. – OneFineDay Feb 24 '17 at 15:04

0 Answers0