none
TableAdapterManager.UpdateAll() not working. RRS feed

  • Question

  • Firstly, I thought you could embed image URLS ? so you can see screen shots etc. I can't see the image tags??

     

    This seems to be a common problem, i have seen some threads but no definitive answers, so I was wondering if you guys can help me.

     

    The problem seems to arise, it would seem, when trying to update records into the database when auto generated TableAdapters, BindingSources and TableAdapterManagers are used in conjunction with more than 1 table in the dataset and have dragged onto your form(s) some ‘details View’ fields from the DataSet from more than 1 table.

     

    The problem – TableAdapterManager.UpdateAll Is executed but does not update the DB record. No error is encountered the command is simply ignored for some reason. The DataSet record is updated. If you reload the records or the form, the data reverts back to what it was and your changes are lost. Line Breaks show that the TableAdapterManager.UpdateAll is indeed processed and does not throw any error of any kind.

     

    My Application: - VB – VS.NET 2010 framework v4 (not client prof) and SQL Server 2008. This has 2 tables.

    Objective: - To maintain a list of customers and an associated Employer as the contact for that company.

     

    Customers – Basically it’s a list of companies.

    customer_id (PK auto-generated)

    customer_name, contact_id (fk to Contact table)

    billing_contact_id (fk to Contact Table)

    shippingagent_id (fk to Agent Table

    customer_tele

    etc

     

    Contacts Baically it’s a list of people’s names.

    Contact_id (PK auto-generated)

    Contact_name

    Contact_tele

    etc

     

    Agent Same as contacts table except it is form Shipping Agents

    Agent_id (PK Auto-generated)

    etc

     

    Two combo boxes on the form (will eventually be a 3<sup>rd</sup> for Agent) connecting to the same dataset that are both unbound to the customer form. They just list the Names of Contacts in the contacts table from the ContactDataSet. The combo box Shows the names  and holds the PK (contact) value for its destination to the customer.contact_id (fk field) in the customers table. It has a temporary home on the customer form, namely the bound  contact_id field.

     

     

     

    Update Code From the AutoGenerated Save Button

    'Code Autogenterated from the Navigator Save Button
    Me.Validate()
    Me.CustomersBindingSource.EndEdit()
    Me.CustomersTableAdapterManager.UpdateAll(CustomersDataSet)
    
    'My ComboBox Code
    Private Sub cboContact_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboContact.DropDownClosed
    'Set the Contact_id value into the Customer Record
    Contact_idTextBox.Text = cboContact.SelectedValue
    'Call the save and diasable sub
    save_disable()
    End Sub
    
    
    
    
    Private Sub save_disable()
    'Update and Refill the dataset to show the changes
    Try
    Me.Validate()
    Me.CustomersBindingSource.EndEdit()
    Me.CustomersTableAdapterManager.UpdateAll(CustomersDataSet)
    'Me.CustomersTableAdapter.Fill(Me.CustomersDataSet.customer)
    Company_nameTextBox.Focus()
    'disable cboContact
    cboContact.Enabled = False
    cboBillingContact.Enabled = False
    ToolStripStatusLabel1.Text = "Record Updated"
    
    Catch ex As Exception
    MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Exit Sub
    
    End Try
    
    End Sub
    

    CustomerDataSet

    [IMG]http://fdm8fa.bay.livefilestore.com/y1pbfcwaJKHbIc-lMPqsCC9YQqA2iTFW9HCFCY9T7qExqrjYnHs9uYbZlP02U6E8D4vkDpqA6jzZHUlYcNRg-wzxPnPAyHLZS3q/CustomersDataSet.jpg?psid=1[/IMG]

    CustomerForm

    [IMG]http://fdm8fa.bay.livefilestore.com/y1prdI96qMVzxXnHAL7_bs0UUA_XIIAJVRSgfrIBlC2O7vdlmMHiLZH8tnr0K4mcafvfcUZ0CPtSbtb3NPadoDYVQu2gRHJxPxI/CustomerForm.jpg?psid=1[/IMG]

    TableAdapterManager

    [IMG]http://fdm8fa.bay.livefilestore.com/y1px4UpBxBtwp0yFZhrqCyhO0zVsyrQ0_drzeC72x-1jCv6dn8N0Sy-37_vbIdpjzQgvGjrBIhlVilkweskFF8gEc49-31ASYFE/TableAdapterManager.jpg?psid=1[/IMG]

     

    Can anyone help with this. I would really appreciate it. It is frustrating to say the least. If I need to provide anything else that may help you experts just let me know.

    lundi 28 février 2011 12:41

Toutes les réponses

  • You might start by setting a breakpoint right before UpdateAll and see whether dataset contains modified rows.

    Miha Markic [MVP C#] http://blog.rthand.com
    mardi 1 mars 2011 10:08
  • Hi Hullster,

    If you are using access database (MDB), then need to check whether there is a duplicate MDB in your debug folder.

    If both answers are yes, then that means each time your program only updates MDB file in the debug folder.

    The thread below is the issue I explained above 

    Why does my database store data to my dataset temporarily

    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/d8b6db17-b622-4de5-949c-f948a5c4dcc7/#1777ee16-660e-48ca-acc6-6555f2cb1a7e

    Regards

     

    vendredi 4 mars 2011 13:11
  • It is a SQL server DB, not using Access.

    samedi 5 mars 2011 14:26
  • Is it possible that you are updating wrong database (using connection string defined at design time)? - Check out connection strings.

    Are adapters properly configured? I'd check their source code.

    Did you try running SQL Server Profiler?


    Miha Markic [MVP C#] http://blog.rthand.com
    samedi 5 mars 2011 17:54
  • If you are using a TableAdapterManager added to the form by design time, make sure that you have also added all relevant DataAdapters and use the TableAdapterMgr properties window reference those adapters.
    mercredi 31 août 2011 15:16
  • I know this is an old post, but i've been stuck on the same issue all day. I'm using C# Visual Studio 2010 with a local sql compact db.  Followed the msdn walkthrough tutorial and have the following code to save:

                try
                {
                    int ret = 0;
                    this.Validate();
                    this.diseaseBindingSource.EndEdit();
                    ret = this.tableAdapterManager.UpdateAll(this.diseaseDataSet);
                    MessageBox.Show("Update successful");
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Update failed " + ex.ToString());
                }

    No exceptions are thrown and the popup "Update successful" is displayed. The 'UpdateAll' method correctly returns the number of items that have been added. If I examine the dataset before calling update, the new rows are present. After update is called, I examine the sql database and the new rows do not appear there.

    Any help much appreciated.

    dimanche 26 août 2012 18:31
  • I'd examine all the items that Miha mentioned in his post, mainly the suggestion to check the connection strings to be sure you're updating the correct database. Try debugging, set a breakpoint on the UpdateAll() line and check the tableAdapterManager.Connection.ConnectionString.

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    dimanche 26 août 2012 22:29
  • Set the Primary Key in SQL Table.
    jeudi 25 juin 2015 18:35
  • Nelson, 

    The posters give for me the impression they are guessing it is a fault of the system which has been done by tenthousand right and by them wrong. 

    However, developers who write a long post and then tell "it does not work" are not high in my range of those from who I think it are developers. 

    Also there was a change in the use of the dataset in version 2010 where was added the possibilities for testing copy to newer, which is mostly not investigated by those who post this question.

    Moreover the problem could have been like wise you say. 

    However, most of all I think it has to do with the attitude needed for programmers to solve problems which seems not high trained by those who posted the messages. 


    Success
    Cor


    vendredi 26 juin 2015 10:50
  • Hi Hullster,

    If you are using access database (MDB), then need to check whether there is a duplicate MDB in your debug folder.

    If both answers are yes, then that means each time your program only updates MDB file in the debug folder.

    The thread below is the issue I explained above 

    Why does my database store data to my dataset temporarily

    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/d8b6db17-b622-4de5-949c-f948a5c4dcc7/#1777ee16-660e-48ca-acc6-6555f2cb1a7e

    Regards

     

    You are right. By default, the mdb is copied to the bin\debug or bin\release folder upon build. In effect, every data change made is overridden each time the application is run.

    The solution is to select the mdb file in Solution Explorer and set the Copy to Output Directory property to Copy if newer.

    Cheers.


    dimpant

    samedi 10 octobre 2015 12:42
  • considering the guy is only probably following a Microsoft Walkthrough, I would say your comment is arrogant and elitist in the extreme. I could also recommend to you a decent English language school if you so wish. Otherwise, stick to your mother tongue. 
    mardi 3 novembre 2015 23:27
  • I've been doing this for a number of years and have often encountered this problem. I've usually seen it when I have a secondary table connected with a key. To start with, I always set up my database to 'Copy if newer' or 'Do not Copy' (Use 'Do not copy' and you'll never lose data). Either way, I have still have had the problem that '.UpdateAll' doesn't work.

    The Try function never catches an error, but some tables still don't get updated using TableAdapterManager.UpdateAll function. I have never figured it out. No error, no break, and no data.

    The following solution comes from the Visual Studio 2005 days, and I've never seen it fail. You may have several TableAdapters if you use several tables in your application, so make sure you update the correct TableAdapter.

    Make sure you do an EndEdit on ALL BindingSources or you won't update the data.

    Me.Validate()
    BindingSource1.EndEdit()
    BindingSource2.EndEdit()
    
    If Me.MyDataSet.HasChanges then
       Dim drModified() As DataRow = Me.MyDataSet.MyTable.Select("", "", DataViewRowState.Added Or _
       DataViewRowState.ModifiedCurrent)
    
       If drModified.Count > 0 Then
          MyTableAdapter.Update(drModified)
       End If
    
       Dim drDeleted() As DataRow = Me.MyDataSet.MyTable.Select("", "", DataViewRowState.Deleted)
       If drDeleted.Count > 0 Then
          MyTableAdapter.Update(drDeleted)
       End If
    
    End If




    • Modifié apalix mardi 10 octobre 2017 21:59
    mardi 10 octobre 2017 21:55
  • Hi Hullster,

    If you are using access database (MDB), then need to check whether there is a duplicate MDB in your debug folder.

    If both answers are yes, then that means each time your program only updates MDB file in the debug folder.

    The thread below is the issue I explained above 

    Why does my database store data to my dataset temporarily

    http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/d8b6db17-b622-4de5-949c-f948a5c4dcc7/#1777ee16-660e-48ca-acc6-6555f2cb1a7e

    Regards

     

    『if you are using access database (MDB)』 >>> this help resolve the blind spot again........
    mercredi 7 février 2018 15:32
  • hi there,

    Something to check when TableAdapterManager.UpdateAll() does not Update.

    In my case it was just 1 table out of 3 that was not updating, the others were fine.

    Now somehow one of the TableAdapterManager's TableAdapters had become unset to "[none]".

    Now the interesting thing here is that Fill Methods fill associated data objects with this property Unset. They just do not Update. It was easy for me to assume these Data Access Objects were set up correctly because of the successful Fills. 

    Just check this one, 'cos its not too deep.

    dimanche 3 février 2019 18:14
  • If anybody is still interested in this problem being resolved: I have filed a "feedback" in Visual Studio, at 

    https://developercommunity.visualstudio.com/content/problem/785029/tableadaptermanager-updateall-fails-to-update-rela.html

    Please go and "vote" for it. Microsoft in their triage process is looking at whether this problem is worth fixing by looking at the "social support" of it.

    lundi 21 octobre 2019 13:35