Results 1 to 4 of 4

Thread: Updating a Data Set

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2017
    Posts
    18

    Updating a Data Set

    Hello everyone, I'm having issues with a form that shows, within a DataGridView, all the orders within a Table, when I click on any line a new Form shows up and I edit the order. When I finish making the changes, even though I tried to update the DataGridView control, the order's total remains unchanged, so when I close the form and load it up again, that's when I see the new total. I debugged and found out the DataSet where the DataGridView is getting data from, is not updating so that's why I see the old total. How can I force the DataSet to update and get the whole Orders table again?

    Thanks

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Updating a Data Set

    If you're using a BindingSource you can call it's ResetBindings method to update any controls the BindingSource is bound to.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Updating a Data Set

    If it's not working then you did it wrong. If we can't see what you did then we can't see what you did wrong.

    That said, there's no "forcing" the DataSet to update. You presumably get the existing data from fields of the DataRow or DataRowView bound to the row they clicked in order to pass it to the new form. You simply set those same fields with the new data and the grid will reflect that change. If you pass the DataRow or DataRowView to the dialogue then it can do the updating, or you can pass in the individual values and then get the individual values back out again and update the row in the main form. For an example of the former, follow the CodeBank link in my signature below and check out my thread on Updating A Grid Row.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Updating a Data Set

    My guess is that, like a lot of people, you're doing things backwards. In this situation, a lot of people have the dialogue save the changes to the database and then wonder why the grid in the main form doesn't change. That's because they are not changing it. What you should be doing, as described above, is making the changes to your DataTable, and thus your grid, first. You then save the changes from the DataTable back to the database and that is done in the main form. The dialogue doesn't know anything about the database. All data access happens in the main form, not spread out over multiple forms.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width