title: Updating DataSource of DataGridView - old rows not removed
body: <p>I have an application with DataGridView. I use a SQLite database and set its table as a DataSource to my DataGridView: I'm getting a DataSet using SQLiteDataAdapter and setting it as a DataSource:</p>
  
  <pre><code>grid.AutoGenerateColumns = false;
  grid.DataSource = ds.Tables[0].DefaultView;
  
  
  grid.Columns["criteriaId"].DataPropertyName = "rowid";
  grid.Columns["criteriaName"].DataPropertyName = "name";
  grid.Columns["criteriaDesc"].DataPropertyName = "description";
  grid.Columns["criteriaDirection"].DataPropertyName = "direction";
  </code></pre>
  
  <p>So far everything seems to be working as I want. But I want to update this DataSource, replacing all rows with other data from another dataset I got from another source. So I wrote:</p>
  
  <pre><code>var originalDs = grid.DataSource as DataView;
  var originalTable = originalDs.Table;
  originalTable.Rows.Clear();
  
  foreach (DataRow row in ds.Tables[0].Rows)
  {   
      var newRow = originalTable.Rows.Add();
  
      foreach (DataColumn column in ds.Tables[0].Columns)
      {
          object item = row[column];
          var columnName = column.ColumnName;
          if (originalTable.Columns[columnName] != null)
          {
              newRow[columnName] = item;
          }
      }
  }
  </code></pre>
  
  <p>Still, it works as expected, all rows in my DataGridView are replaced with new data. BUT. Now I am trying to update underlying database with these changes, so I am calling:</p>
  
  <pre><code>var cmdb = new SQLiteCommandBuilder(adapter);
  adapter.UpdateCommand = cmdb.GetUpdateCommand();
  
  var cm = (CurrencyManager)grid.BindingContext[grid.DataSource, grid.DataMember];
  cm.EndCurrentEdit();
  
  grid.EndEdit();
  adapter.Update(ds.Tables[0]);
  </code></pre>
  
  <p>Where adapter is a SQLiteDataAdapter I used to read data from DB first. And here I'm stuck with a problem: instead of deleting all previous data and saving new rows to a database, all previous records are still in my database and all new rows from a new datasource are added. So it's just adding and not replacing rows. In a line above <code>adapter.Update(ds.Tables[0]);</code> when I debug I can see that ds.Tables[0] has only rows from a new source. So why aren't old rows deleted? What can I do to make it work?</p>
  
  <p>Deletng rows from DB works when I delete rows in DataGridView manually using GUI and then save it all the same way to a database.</p>
  
  <p>Any ideas?</p>