Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Updates to DataSet are not saved after program closes

Posted on 2010-08-24
18
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 33516518
in your function Set :
 Dim Saved As Boolean=False
and try again...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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