Solved

Updates to DataSet are not saved after program closes

Posted on 2010-08-24
18
261 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 500 total points
ID: 33516518
in your function Set :
 Dim Saved As Boolean=False
and try again...
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Backup & Restore 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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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