• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 110
  • Last Modified:

C# Winform Table Adapter suddenly not saving to DB

I have a C# Winform app that I wrote a couple of months ago that has been working fine, but recently has ceased to update my database when Im calling the TableAdapter.Update function. I have this in a try / catch block, and it is not throwing any errors. If I put a Breakpoint on the Update line, I can see all my new values in the various form fields, but it again it doesnt throw any exceptions. My connection string to the DB must be good because my Fill query works.

Below is my code:
 private void SaveButton_Click(object sender, EventArgs e)
        {         
                try
                {
                    this.Validate();
                    this.taEditBindingSource.EndEdit();                  
                    this.taEditTableAdapter.Update(this.ONLINE_STOREDataSet.taEdit);
                    var form = new SaveConfirmed(); //Displays my Custom Confirmation Box
                    form.Show();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Update failed:\n" + ex);
                }
				
        }

Open in new window


Any ideas are appreciated.
0
hhnetworks
Asked:
hhnetworks
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
Does the DataSet have any changes when the Update is called?
0
 
hhnetworksAuthor Commented:
I believe so. When I enter or change data in the List View and if I put a breakpoint at Line 7 in the code above, I can drill into the dataset in debugger and see changes Ive made in the various fields
0
 
Bob LearnedCommented:
Another way to see if a DataSet has changes, there is the DataSet.GetChanges method:

DataSet.GetChanges Method
https://msdn.microsoft.com/en-us/library/a4ey25we(v=vs.110).aspx

For example, if there is a call to AcceptChanges, that the system will change the row states to Unmodified, and there won't be any changes.

Also, does the SqlDataAdapter have an UpdateCommand, InsertCommand, and DeleteCommand?
0
 
hhnetworksAuthor Commented:
Thanks Bob.

Additional debugging revealed that I had an Event Handler elsewhere that was calling the Fill function of my dataset before changes were being saved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now