none
TableAdapter data methods RRS feed

  • Question

  • I have a strongly typed dataset that contains 2 tables - Products and OrderedItems like this:

    Products: ProductID, Name, Description

    OrderedItems: OrderID, ProductID, Quantity.

     

    I would like to have a control that shows the Order details: ProductName, ProductDescription, Quantity. To do that I'm using a join in the OrderedItems Fill method, thus modifying the schema for the OrderedItems table.

    Since the Fill method contains a Join, the GenerateDbDirectMethods is set to false, but I defined Insert/Update/Delete Commands for the table adapter. Obviously, when I insert or update, I'm only inserting/updating the fields of the OrderedItems table, not the Product name and description.

    The problem is that if I add a row or modify a row and call TableAdapterManager.UpdateAll method the changes to the OrderedItems table are not made. Shouldn't that be calling the Insert/Update/Delete Command I defined?

    I then tried adding my own Insert/Update/Delete queries to the tableAdapter but they are created with names such as Insert1, even though no Insert query is available. It's almost as if the db direct methods have been generated.

     

    Any suggestions?

     

     

    • Moved by Kira Qian Monday, November 29, 2010 7:39 AM (From:Windows Forms Data Controls and Databinding)
    Sunday, November 28, 2010 8:00 PM

All replies

  • Hi Ventsislav,

     

    This issue seems a pure ADO.NET issue. It does not relate to Winform databinding. I will move it to the ADO.NET forum for better support.

     

    Sincerely,

    Kira Qian

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Monday, November 29, 2010 7:37 AM
  • OK. Thanks.
    Tuesday, November 30, 2010 2:17 AM
  • Hello,

    Thanks for your thread and post!

    As I understand, you create a types dataset which refer to 2 tables (Products and OrderedItems) in database. Instead of dragging and dropping the two tables directly from database, you wanted to create a datatable (let’s named it ProductOrders?) which could show the detail of the orders which contains these fields: ProductName, ProductDescription, Quantity.

    As you may notice, the dataset designer cannot generate Insert/Update/Delete command for the ProductOrders table, hence, you manually generate them. However, those commands are not executed.

    If I misunderstand you, please correct me.

    If I catch your point, please try the following workaround:
    Please right click the designer and add a new query to insert/update/delete the data you want (follow the wizard):
    https://l2etcq.bay.livefilestore.com/y1pfpXmwfdSmP2KtpObwg5st-Rn9naELnxfKfOXvhjCC_PwxP308g_OMHk6IfREC8qgfE-N8ogNaD2fl1XTaWVJA1WK7lIInF9M/query.png?psid=1

     

    And then you could execute the query, for example:

    DataSet1TableAdapters.QueriesTableAdapter adpter = new DataSet1TableAdapters.QueriesTableAdapter();

    adpter.UpdateProductUnitPrice(1432.55m, pid);

    //


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    • Edited by liurong luo Tuesday, November 30, 2010 5:17 AM link
    Tuesday, November 30, 2010 5:15 AM
  • That's what I'm doing now, but with this approach I lose the advantages that the tableadaptermanager presents. For each table I have to call Insert/Update/Delete instead of simply calling the adaptermanager's update all method.

    Isn't there a better way?

    Tuesday, November 30, 2010 10:04 PM
  • Why do I get forbidden on this link?

     

    If I catch your point, please try the following workaround:
    Please right click the designer and add a new query to insert/update/delete the data you want (follow the wizard):
    https://l2etcq.bay.livefilestore.com/y1pfpXmwfdSmP2KtpObwg5st-Rn9naELnxfKfOXvhjCC_PwxP308g_OMHk6IfREC8qgfE-N8ogNaD2fl1XTaWVJA1WK7lIInF9M/query.png?psid=1

    Friday, December 3, 2010 8:15 AM
  • Thanks a lot for your information. It is OK now.


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Friday, December 3, 2010 9:01 AM
  • I'm still not following what the work-around is. If you suggest I create a new table in the dataset that combines the Product and Order Tables - how is that going to help with the insert and update? There is not corresponding table in the database.

    I tried clicking on the table adapter, select properties, then added an Insert/Update/Delete commands, but those don't appear to be executing automatically. I would call the UpdateAll on the table adapter manager but the dataset changes does not appear to get committed.

    Tuesday, December 7, 2010 3:08 AM
  • I have to solve this issue one way or the other. It has been slowing me down significantly, and is starting to introduce ugly work-arounds. It can't be this difficult, I can't believe this is not a very common issue.

     

    Let me see if I understand correctly the information so far:

    1. The dataset adapter will not generate default queries if the data table is constructed with a join. (The fill method has a join.)

    2. If I add Select/Insert/Delete/Update commands for any such table adapter, they won't be executed when I call the tableAdapter's Update method (or dataset UpdateAll method)

    3. I have to add custom queries to each table adapter that I need to call manually from my code.

    4. If I call the AddNew or Add methods on the tableBindingSource, this will result in a new row being added to the binding source, but since I need to call the Update method on the table those changed rows will not be committed.

     

    Do I undestand everything correctly? What would be the best way to proceed?

     

    Sunday, December 12, 2010 4:34 PM
  • Ventsislav,

    I was reviewing this problem and found that it's better to troubleshoot this issue live/on call.

    Your question falls into the paid support category which requires a more in-depth level of support.  Please visit the below link to see the various paid support options that are available to better meet your needs:

     

    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

     

    Regards,
    Jay [MSFT]


    Jay Akhawri
    Monday, December 27, 2010 9:32 PM
  • Hi Vent,

    A small question. Is there any specific need of using typed dataset and table adapter.

    My openion is when you use the wizard to generate the typed dataset and table adapter , you loose control over the application and how it talk to the database.

    I think you can implement the solution much easily using untyped dataset.


    Snehadeep(MSFT) SQL Developer Team
    Tuesday, December 28, 2010 6:04 AM
  • What exactly does a typed dataset give you?

    Does it save you having to define every data item in a tables data type?

     


    John F Lundy
    Tuesday, December 28, 2010 6:43 AM
  • @Snehadeep ... you can utilize Typed DataSets without using the wizard and without using TableAdapters. I agree with you about how that causes you to lose control of your application, but the answer is to avoid using the TableAdapters, not to avoid using Typed DataSets. See my blog post about creating an .XSD without TableAdapters:

    http://geek-goddess-bonnie.blogspot.com/2010/04/create-xsd.html

    @WebDataBases (John) ... I believe we've had a few posts back and forth about this in the comments of my blog post. ;0)


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, December 29, 2010 3:40 PM