0

I have a dataset with about 6 rows. I can confirm the dataset's table is filled by getting its row count. I fill the dataset with rows from a previously filled dataset from a different source. According to all the articles I've found here and on the internet in general, I'm supposed to call dataset.datatable.AcceptChanges() then tableadapter.Update(dataset.datatable), but the new data is never recorded on the new database. This is what I'm doing:

using FbConnection originalDB = new FbConnection($@"data source=localhost;initial catalog={AppDomain.CurrentDomain.BaseDirectory}OLD_DATABASE.FDB;user id=SYSDBA;password=masterkey");
using FbConnection destinationDB = new FbConnection($@"data source=localhost;initial catalog={AppDomain.CurrentDomain.BaseDirectory}NEW_DATABASE.FDB;user id=SYSDBA;password=masterkey");

var originalset = new DataSet1();
var destinationset = new DataSet1();

var groupsTableAdapter = new DataSet1TableAdapters.GroupsTableAdapter() { Connection = originalDB };

groupsTableAdapter .Fill(originalset.GroupsTable);

groupsTableAdapter= new DataSet1TableAdapters.GroupsTableAdapter() { Connection = destinationDB };

foreach (DataSet1.GroupsRow groupRow in originalset.GroupsTable.Rows)
{ 
            destinationset.GroupsTable.ImportRow(groupRow);
            Console.WriteLine($"ROW PROCESSED> {groupRow.GroupID}");
}
int rows = destinationset.GroupsTable.Rows.Count;
Console.WriteLine(rows + " added");
destinationset.GroupTable.AcceptChanges();
GroupsTableAdapter.Update(destinationset.GroupsTable);

When I check the database with a third-party software, the table is empty. What am I doing wrong here?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Artur S.
  • 185
  • 3
  • 15
  • 1
    Where did you get that idea about `AcceptChanges`? The documentation says the opposite: `The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed.` - any changes queued for the db are cancelled!. You want the opposite: set `da.AcceptChangesDuringFill` to false on your dataadapter so that all rows loaded from the source are treated as new. – Ňɏssa Pøngjǣrdenlarp Oct 03 '20 at 16:07
  • use http://fbprofiler.sf.net to see which requests are actually delivered to your database. The usual reason is that your applicaiton did not commit database transaction. – Arioch 'The Oct 05 '20 at 11:41
  • @ŇɏssaPøngjǣrdenlarp I read it at https://stackoverflow.com/questions/7055799/how-to-save-the-dataset-after-making-changes-to-the-database and https://stackoverflow.com/questions/15824967/datatable-importrow-is-not-adding-rows – Artur S. Oct 05 '20 at 15:35
  • (Un)fortunately, we finally ditched the third-party database, and are now using our own. – Artur S. Oct 09 '20 at 19:11

0 Answers0