• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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.

0
Jeenyusx10
Asked:
Jeenyusx10
  • 10
  • 7
1 Solution
 
John (Yiannis) ToutountzoglouCommented:
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
 
John (Yiannis) ToutountzoglouCommented:
in your function Set :
 Dim Saved As Boolean=False
and try again...
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
John (Yiannis) ToutountzoglouCommented:
I am using this function also ...many many times ...It Works Without problems
0
 
John (Yiannis) ToutountzoglouCommented:
Also in your CancelButton Click
replace
SuppliersBindingSource.CancelEdit()
with
me.AndersenDataSet.RejectChanges..
0
 
Jeenyusx10Author Commented:
Thanks again!
0
 
John (Yiannis) ToutountzoglouCommented:
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) ToutountzoglouCommented:
@benzadon
This is done by the boolean Value...
This Function Is a very good function ...it saves data properly ...


0
 
John (Yiannis) ToutountzoglouCommented:
I think ....you are missing something
0
 
Jeenyusx10Author Commented:
I must be going crazy because it IS actually working right now..
0
 
John (Yiannis) ToutountzoglouCommented:
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) ToutountzoglouCommented:
did your data saved finally?
0
 
Jeenyusx10Author Commented:
yes. It is working properly
0
 
John (Yiannis) ToutountzoglouCommented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now