I have few tables in the database with parent table say P is having 1:1 relation with some child tables whereas having 1:M relation with other child tables.

For this I have added DataSet at design time by 'Add -> New Item -> DataSet -> DataSet1.xsd'
So, I have all the required tables along with their 1:1 or 1:M relations.

I have applied some filter on main table adapter so that only selected records from parent table and their related child records are populated in the dataset. And finally, I want to write this data from DataSet to Xml file.

But, I am getting one issue - the final dataset that I am getting is having all the records from child table. Instead it should have only those child records for which parent table is having related records.

I am using following code -

ParentDataSet parentDataSet = new ParentDataSet();
ParentTableAdapter parentTableAdapter = new ParentTableAdapter();
parentTableAdapter.Fill(parentDataSet.ParentTable, column1Value); // All fine until here as I have applied filter in tableAdapter SQL
ChildTableAdapter childTableAdapter = new ChildTableAdapter();
//returns all rows in the child table -- shouldn't it return only those child records for which parent dataset table is having records??
childTableAdapter.Fill(parentDataSet.ChildTable);
parentDataSet.WriteXml(xmlFilePath);

1 Answer
1

By default, the DataSet designer sets the DataRelations between
parent-child tables as "Relation Only". This means that the DataSet
will not enforce the foreign key constraints on the client, just your
database...

Try changing the type of the parent-child relation to a foreign key constraint. Then, check the SelectCommand property of the ChildTableAdapter. Is it filtering the data the way you expect?

Thanks for your reply. It didn't solve the issue - So it seems I have to add filter for related tables as well as I have added for parent table.
–
inikiJan 4 '12 at 16:02

I ended up adding filter for parent as well as related child tables :-)
–
inikiMar 6 '12 at 22:48

@iniki Since my answer doesn't actually solve the problem, you should post your solution as a separate answer and accept it. (You can accept your own answer to a question that you asked.)
–
KimberlyMar 7 '12 at 14:52