DataAdapter Update help

Posted on 2005-04-28
Last Modified: 2012-06-27
Hi Everyone,

Here is my scenario, I am retrieving a dataset from a webservice and I would like to update my database with the information from the dataset.  I'm attempting to perform this with a data adapter and I keep stumbling across this error:

"Update unable to find TableMapping"

Here is a sample of what I am working with:

// Variables
SqlDataAdapter adptAppSession;
DataSet dsAppSession;

// Creating the DataAdpater to be used for update
adptAppSession = new SqlDataAdapter("select * from AppSessions", dbConnection);
// Calling the web services
dsAppSession = webService.getAppSessionTable("01/01/2005","01/30/2005");
// Updating the data adapter                        

Can someone please help me with this, it seems like a common thing to do to retrieve a dataset from a webservice and update a database.  What am i missing?? Does the structure of the dataset matter? I thought it would infer a schema and match it to the dataAdapter, do I have to do this implicitly and if so, how do I do it?  Specific code examples would be greatly appreciated.  Thanks

Question by:zozig
    LVL 10

    Expert Comment

    I am not sure that your code makes sense ....

    at which point do you get the error.

    You need to create the dataset from the dataAdapter ... through using


    that will create the dataset which is matched to the dataAdapter and contains the entries recovered by "select * from AppSessions".

    then you get a dataSet from the Web Service. Which is a separate DataSet.

    you then need to use the new dataset to update the existing one ... that will create the new records which will be marked for Insert / Update / Delete
    then when you use the Update() method it will update the DB.
    LVL 23

    Expert Comment

    The thing with ADO.NET 1.x is that Updates use the RowState property of the DataRows. So you'd need Rows that are marked as Modified (the UpdateCommand will be fired), Added (the InsertCommand will be fired) and/or Deleted (the DeleteCommand will be fired)

    also, unless there's table mappings occurring, you'd be better off using the DataTable as well as the GetChanges() method

    // Calling the web services
    dsAppSession = webService.getAppSessionTable("01/01/2005","01/30/2005");

    if (dsAppSession.HasChanges)
    LVL 1

    Author Comment


    I've added some code that utilizes two datasets as you've mentioned, I now get no error but nothing gets updated to the database, here is the code I am using:

    // A new dataset to merge with the one from the web service
    dsSessionData = new DataSet();

    // this is the data set from the webservice
    dsAppSession = webService.getAppSessionTable("01/01/2005","01/30/2005");
    // Merge the dataset with the webservice dataset
    // Update the dataset

    Is that what you are recommending?  If so, why does nothing get updated, I've created xml files from the webservice dataset and confirmed that I am definately getting data back.  Is there another method to use besides merge?  Thanks.

    LVL 10

    Accepted Solution

    Merge should be the correct method to use - if you debug the dataset after the merge can you see that some have a row state of
    Modified / Added / Deleted ? as b1xml2 mentioned the DA.Update method uses these to fire the correct Update / Insert / Delete statements to the DB.

    If you do have these Row States then you may need to add the correct Update / Delete / Insert statements into your data adapter to ensure that you get the correct changes in your DB.
    LVL 1

    Author Comment


    I've inspected the Datset after the merge and I've noticed that the Row state is 'unchanged' for all the rows.  One item that is confusing me is the tablename.  The tablename for the DataSet from the webservice states that the name is "Item" and the table I wish to update is AppSessions.  I've placed a tablemapping on the dataAdapter to see if that would resolve any descrepancies but still no luck.  Any ideas?  Here is the code on the dataAdapter:

    adptAppSession.TableMappings.Add("Item", "AppSessions");
    adptAppSession.MissingSchemaAction = MissingSchemaAction.AddWithKey;


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now