Search code examples
c#.netdatatabledatasetstrongly-typed-dataset

Persist typed dataset after merge with a weak dataset


I have two datasets, first one is generic, second one is typed. I'm trying to update a row and persist it into the database but keep failing. Here is what I'm trying to do:

Load the data into the generic DS

Merge the typed DS with the generic one.

Update rows in typed DS.

Call AcceptChanges on the generic to persist it into the database

//Generic DS
    DataSet ds = GetData();

//Typed Ds
    var gradeTeamConfigDataSet = new GradeTeamConfigDataSet();

//Merge    
    gradeTeamConfigDataSet.tblGradeTeamConfig.Merge(ds.Tables["default"], true, MissingSchemaAction.Ignore);

      //Update
      if (gradeTeamConfigDataSet.tblGradeTeamConfig != null)
             {

                    gradeTeamConfigDataSet.tblGradeTeamConfig.Rows[0].BeginEdit();

                    //Update row

                    gradeTeamConfigDataSet.tblGradeTeamConfig.Rows[0].EndEdit();
             }
    //Persist        
    gradeTeamConfigDataSet.AcceptChanges();

But when checking the database again it has not updated anything! Could any one spot the issue, and give me a solution please?


Solution

  • Have you look at this post

    AcceptChanges only updates your rows in the (in memory) dataset, that is - marks them as "not needed for actual database update". If you want to update your rows to the database, call your tableadapter's Update method.