If the underlying data in your database has changed, the only way to load that information into your dataset is to load it manually. You have a couple of options here, depending on your needs:
- You can discard the existing data and re-fill the data set from your data adapter.
- You can load a second copy of the dataset and use
DataSet.Merge
to bring in any changes. - You can just add your new row into the dataset directly.
However, when you're using strongly typed data sets, the intention is for you to use that object when adding new rows, not to add them to the database via the table adapter. When you add a new row to a table in the data set, it is tracked as "added" in memory. When you then go to save changes from that dataset back to the database via your table adapter, the dataset will call whatever the appropriate InsertCommand
or UpdateCommand
is for the tables. In that way, your database and dataset are synchronized.
The workflow for using typed datasets typically has the following steps, in his order. You can get rather complex with the merge resolution logic and how you handle conflicts, but the basic idea is the same:
dataAdapter.Fill(dataset)
- (make changes to your typed dataset via the typed data rows)
dataChanges = dataSet.GetChanges()
dataAdapeter.Update(dataChanges)
dataSet.Merge(dataChanges)
dataSet.AcceptChanges()