Solved

Updates to DataSet are not saved after program closes

Posted on 2010-08-24
18
255 Views
Last Modified: 2012-05-10
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
Comment
Question by:Jeenyusx10
  • 10
  • 7
18 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516450
Can you  post your update method?
0
 

Author Comment

by:Jeenyusx10
ID: 33516490

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
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33516518
in your function Set :
 Dim Saved As Boolean=False
and try again...
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516527
I am using this function also ...many many times ...It Works Without problems
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516541
Also in your CancelButton Click
replace
SuppliersBindingSource.CancelEdit()
with
me.AndersenDataSet.RejectChanges..
0
 

Author Comment

by:Jeenyusx10
ID: 33516553
Thanks again!
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516556
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
 

Expert Comment

by:benzadon
ID: 33516560
Did you try AcceptChanges() after updating the DataSet?
In your case:
LINE 19:       SuppliersTableAdapter.AcceptChanges()
0
 

Author Comment

by:Jeenyusx10
ID: 33516582
Client = SUpplier.. but I just attempted again and its still not working.. it worked one time though
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516588
@benzadon
This is done by the boolean Value...
This Function Is a very good function ...it saves data properly ...


0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516605
I think ....you are missing something
0
 

Author Comment

by:Jeenyusx10
ID: 33516607
I must be going crazy because it IS actually working right now..
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516624
1.Why you me.BindingSOurce.Addnew in your Form Load ....
2.Did you check your data in your sql serveR?
0
 

Author Comment

by:Jeenyusx10
ID: 33516629
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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516634
did your data saved finally?
0
 

Author Comment

by:Jeenyusx10
ID: 33516636
yes. It is working properly
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33516645
Just also use Me.AndersenDataSet.RejectChanges in you cancel Button
0
 

Author Comment

by:Jeenyusx10
ID: 33517223
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now