Updates to DataSet are not saved after program closes

I have written a program in VB. THe dataset contains a Client table. I can add clients information, and the dataset is updated, and I can then retrieve the information from another screen to validate that it did in fact update. However, when I close and re-open the program , the data is no longer in the dataset.

It seems that I am missing a final step of some sort.

Jeenyusx10Asked:
Who is Participating?
 
John (Yiannis) ToutountzoglouConnect With a Mentor Instructor Multiengine PilotCommented:
in your function Set :
 Dim Saved As Boolean=False
and try again...
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Can you  post your update method?
0
 
Jeenyusx10Author Commented:

Public Class AddSupplier


    Private Sub AddSupplier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'AndersenDataSet.Suppliers' table. You can move, or remove it, as needed.

        Me.SuppliersTableAdapter.Fill(Me.AndersenDataSet.Suppliers)
        Me.SuppliersBindingSource.AddNew()
        MdiParent = MDIParent1

    End Sub
    Private Function Save() As Boolean
        Dim Saved As Boolean

        If AndersenDataSet.HasChanges Then
            Try
                Dim MYUpdates() As DataRow = AndersenDataSet.Suppliers.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent)
                Me.SuppliersTableAdapter.Update(MYUpdates)

                Saved = True

            Catch ex As SqlException
                MessageBox.Show(ex.Message)

            End Try
        End If
        Return Saved
        MsgBox("Nothing to save")
    End Function

    Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
        Me.Validate()
        Me.SuppliersBindingSource.EndEdit()
        If Me.Save Then
            MessageBox.Show("Ok", "Changes Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        Me.Close()
    End Sub

    Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelButton.Click
        SuppliersBindingSource.CancelEdit()
        Me.Close()
    End Sub

End Class

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
I am using this function also ...many many times ...It Works Without problems
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Also in your CancelButton Click
replace
SuppliersBindingSource.CancelEdit()
with
me.AndersenDataSet.RejectChanges..
0
 
Jeenyusx10Author Commented:
Thanks again!
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Also if your dataset includes also client table you have ti declare it in your function...
Dim MYUpdates() As DataRow = AndersenDataSet.YourClientTable.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent)
                Me.SuppliersTableAdapter.Update(MYUpdates)
0
 
benzadonCommented:
Did you try AcceptChanges() after updating the DataSet?
In your case:
LINE 19:       SuppliersTableAdapter.AcceptChanges()
0
 
Jeenyusx10Author Commented:
Client = SUpplier.. but I just attempted again and its still not working.. it worked one time though
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
@benzadon
This is done by the boolean Value...
This Function Is a very good function ...it saves data properly ...


0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
I think ....you are missing something
0
 
Jeenyusx10Author Commented:
I must be going crazy because it IS actually working right now..
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
1.Why you me.BindingSOurce.Addnew in your Form Load ....
2.Did you check your data in your sql serveR?
0
 
Jeenyusx10Author Commented:
Not entirely sure. I posted a question a few days ago and that was part of your solution..You have answered all my questions in the past week
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
did your data saved finally?
0
 
Jeenyusx10Author Commented:
yes. It is working properly
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Just also use Me.AndersenDataSet.RejectChanges in you cancel Button
0
 
Jeenyusx10Author Commented:
It seems that everything saves fine until I make some change to the code, and then the data disappears..

Should this be happening. Also, I understand that DataSets are supped to automatically push updates back to the origional SQL Database...

This is not the case so far. If I open up the management studio, the updates are not there... then I debug the program and the data still exists within the program...

That is, untill I make changes to the code. This tells me that the dataset is not properly updating to the database...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.