Take the 2-minute tour ×

I have a strongly typed dataSet that calls some stored procedures.In one case I add some data in the database using the strongly typed data set.The data gets added to the database but for some reason the new data is not being displayed.

This leads me to believe that I have to somehow refresh the strongly typed dataset after I add a new item.I am not sure what code I should post here but I will post the code that adds the elements to the database:

var addBookAdapter = new QueriesTableAdapter();           


This is the stored procedure that does this:

    @Name nvarchar(MAX),
    @Author nvarchar(MAX),
    @Description nvarchar(MAX),
    @Date date  ,
    @CategoryId int
    INSERT INTO Books (Name , Author , Description , PublicationDate , CategoryId)
    VALUES (@Name , @Author , @Description , @Date , @CategoryId)

As I already mentioned this works.The new item gets added to the db but they are not displayed

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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()
share|improve this answer
To get started, just configure the update query in the TA to use your stored procedure. Then write code to add the new row to the dataset, and call update on the TA. Depending on your circumstances, you may or may not need the full GetChanges workflow in Michael's answer. If you are new to ADO.Net, I'd try getting familiar with the simple approach first. –  peterG Mar 3 '13 at 16:38

Your Answer


