title: DataSet changes not being persisted to database
body: <p>I have a windows form with a number of data-bound fields relating to a client. Additionally, I have a DataGridView showing orders for the currently displayed client. This is achieved using the design-time Visual Studio controls (e.g. a project DataSet, BindingSources TableAdapters and a TableAdapterManager.</p>
  
  <p>When loading the form to edit an existing client it is populated using a (custom) FillByID method on the ClientsTableAdapter to filter the DataSet to the single, relevant client. This loads their details into the client fields, and populates the orders DataGridView correctly.</p>
  
  <p>Any changes I make to a client's orders (within the DataGridView) are persisted to the database when saving, however, none of the client detail fields are. They are editable, and show the correct details when loading, but no changes that are made are saved when the form is closed. I have tried two separate ways of persisting them now, the first being inline with the order saving:</p>
  
  <pre><code>this.Validate();
  this.clientordersBindingSource.EndEdit();
  this.clientsBindingSource.EndEdit();
  this.clientordersTableAdapter.Update(projectDataSet.clientorders);
  this.clientsTableAdapter.Update(projectDataSet.clients);
  </code></pre>
  
  <p>...and the second using the <a href="http://msdn.microsoft.com/en-us/library/4esb49b4(v=VS.80).aspx" rel="nofollow noreferrer">multiple table example</a> on MSDN. Sadly, neither of these methods work with regards to the client details - although changes to client orders <strong>are</strong> persisted in both cases.</p>
  
  <p>My clients table has the following structure:</p>
  
  <pre><code>refnumber, title, forename, surname, gender, dob, contactnumber
  </code></pre>
  
  <p>The clientsTableAdapter has the following CommandText strings for the DeleteCommand, InsertCommand, SelectCommand and UpdateCommand respectively:</p>
  
  <pre><code>DELETE FROM clients WHERE (refnumber = @Original_refnumber)
  INSERT INTO clients (refnumber, title, forename, surname, gender, dob, contactnumber) VALUES (@refnumber, @title, @forename, @surname, @gender, @dob, @contactnumber)
  SELECT refnumber, title, forename, surname, gender, dob, contactnumber FROM clients
  UPDATE clients SET refnumber = @refnumber, title = @title, forename = @forename, surname = @surname, gender = @gender, dob = @dob, contactnumber = @contactnumber WHERE (refnumber = @Original_refnumber)
  </code></pre>
  
  <p>When saving, if I add a variable to capture the result of this line:</p>
  
  <pre><code>var res = this.clientsTableAdapter.Update(projectDataSet.clients);
  </code></pre>
  
  <ul>
  <li><code>projectDataSet.clients.Count == 1</code></li>
  <li><code>projectDataSet.clients.Rows[0].ItemArray</code> shows the modified fields.</li>
  <li><code>projectDataSet.clients.Rows[0].RowState == Unchanged</code></li>
  <li><code>res == 0</code></li>
  </ul>
  
  <p>Please can anyone offer any hints? This has been driving me insane for days!</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I recreated the form from scratch using the Visual Studio designer, then copied &amp; pasted all the code from the original form. It now works. I guess something must have been wrong in the Designer.cs file with one of the datasources/databinding fields.</p>
  
  <p>Thanks for the helpful debugging hints, ewall and Ladislav Mrnka.</p>