using DataRelation to get child data from DataAdapter RRS feed

  • Question

  • There are two tables, Question and Instruction.  The Question table has an InstructionId.  The DataSet has a DataAdapter and DataTable for each table. 

    The goal is to get the Instruction data for a only the Questions that are queried.

    Once the parent (Instruction)/ child (Question) relationship is setup in the DataSet, what needs to happen to populate both datasets correctly? 

    Monday, June 15, 2009 9:33 PM


All replies

  • See if my example helps:

    Scroll to bottom
    John Grove - TFD Group, Senior Software Engineer, EI Division,
    Tuesday, June 16, 2009 4:30 PM
  • John,

    Thank you for the example, I got it working, though there is a minor bug in it.  In the comboBox1_SelectedIndexChanged() event handler, you have:

    compFile = new DataTable();

    There was no compFile variable defined so I defined it right there and all was well.

    The only catch is this:  I am looking for a way to use the relationship in doing the actual SQL select, so if I only get back a subset of customers, I only have their orders in memory, not all 800+ orders.  From the digging I have done since I posted the Q, this cannot be done other than a select statement that controls which orders come back.  Is this correct?

    Tuesday, June 16, 2009 5:22 PM
  • You can certainly do that if your information is joined in disparate DataTables and appropriately joined using the DataRelation classes and these DataTables reside within a DataSet. However, you will probably have to create the resultant table after the comboBox_SelectedIndexChanged event handler and then produce the results you are looking for as a result of the join.

    John Grove - TFD Group, Senior Software Engineer, EI Division,
    Tuesday, June 16, 2009 7:12 PM