Results 1 to 40 of 57

Thread: [RESOLVED] refresh combobox values after updating its datatable and adapter

Hybrid View

  1. #1
    New Member
    Join Date
    Mar 2012
    Posts
    2

    Re: [RESOLVED] refresh combobox values after updating its datatable and adapter

    I think you guys are missing the big picture. There is a difference between a dataset and the database. A dataset is a copy of the data in the database. If you update the data in the Database's datatable you have to reload the data into the dataset datatable. Also, if you update the data in a dataset, you have to save it using the update method. Otherwise you are only changing the copy of the data, not the data. When you reload the dataset, the data you added will be missing.

    This code obviously doesn't work for every scenario, just keep in mind that you have to reload the data from the table before you can see it.
    Me.MachinesTableAdapter.InsertMachineName(tbxMachineName.Text)
    Me.MachinesBindingSource.EndEdit()
    Me.MachinesTableAdapter.Update(Me.FlowMetersDataSet.Machines)
    Me.MachinesTableAdapter.Fill(Me.FlowMetersDataSet.Machines)


    'Returning From a dialog
    Dim Result As DialogResult
    Result = dlgNewMachine.ShowDialog()
    If Result = DialogResult.OK Then Me.MachinesTableAdapter.Fill(Me.FlowMetersDataSet.Machines)
    Last edited by TrippingCobras; Mar 6th, 2012 at 07:14 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] refresh combobox values after updating its datatable and adapter

    Quote Originally Posted by TrippingCobras View Post
    There is a difference between a dataset and the datatable. A dataset is a copy of the data in the datatable.
    a dataset is a collection of datatables + if you change the datatable it changes

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

    Re: [RESOLVED] refresh combobox values after updating its datatable and adapter

    Quote Originally Posted by TrippingCobras View Post
    I think you guys are missing the big picture. There is a difference between a dataset and the datatable.
    There's a difference alright, but not the one you seem to think there is. A DataSet is essentially an in-memory representation of a database. A DataTable is basically an in-memory representation of a database table. Just as a database contains tables and relations between them, so a DataSet contains DataTables and DataRelations. A DataSet has a Tables property, which is a collection of DataTables, and a Relations property, which is a collection of DataRelations.

    When you call Fill on a DataAdapter or TableAdapter you are populating a DataTable. Even if you pass a DataSet as an argument, you are populating one of the DataTables in its Tables collection. When you call Update on a DataAdapter or TableAdapter you are saving changes from a DataTable. Even if you pass a DataSet as an argument, you are saving changes from one of the DataTables in its Tables collection.

    Just as a database table has columns to describe the data and rows to contain it, so a DataTable has a Columns property, which is a collection of DataColumns, and a Rows property, which is a collection of DataRows.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    New Member
    Join Date
    Mar 2012
    Posts
    2

    Re: [RESOLVED] refresh combobox values after updating its datatable and adapter

    Quote Originally Posted by jmcilhinney View Post
    There's a difference alright, but not the one you seem to think there is. A DataSet is essentially an in-memory representation of a database. A DataTable is basically an in-memory representation of a database table. Just as a database contains tables and relations between them, so a DataSet contains DataTables and DataRelations. A DataSet has a Tables property, which is a collection of DataTables, and a Relations property, which is a collection of DataRelations.

    When you call Fill on a DataAdapter or TableAdapter you are populating a DataTable. Even if you pass a DataSet as an argument, you are populating one of the DataTables in its Tables collection. When you call Update on a DataAdapter or TableAdapter you are saving changes from a DataTable. Even if you pass a DataSet as an argument, you are saving changes from one of the DataTables in its Tables collection.

    Just as a database table has columns to describe the data and rows to contain it, so a DataTable has a Columns property, which is a collection of DataColumns, and a Rows property, which is a collection of DataRows.
    I meant database smart guy. You can manipulate the dataset without committing the changes to the actual database. Many people don't understand this and find themselves wondering why all of their data dissapeared. And Paul apparently hasn't figure this out either.

    Chances are the people who originally asked the question are using table adapters (as in ADO.Net). People make the mistake of adding the data to the table adapter, then can't see it on the dataset because they didn't perform a fill method. Another thing that happens is that someone changes the dataset, then doesn't write the the information back to the database.

    Why do I bother with you guys? The post was never really properly addressed, but you guys are sure to jump on someone adding input.

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