[RESOLVED] Search Related Tables
Hi,
Is there any way I can use a bindingsource for a parent table (tblPerson) to search for a value belonging to it's related child table (tblAddress) or do i have to search tblAddress for the value, return the FK and then search tblPerson for the FK.
Hope this is clear,
Thanks for any help
Ger
Re: Search Related Tables
If both DataTables are in the same DataSet and there is a DataRelation between them then you can use the GetChildRows method of the parent DataRow.
Re: Search Related Tables
Thanks for the response,
So if i was looking for a Person (FirstName & Surname) from Dublin I'd have to increment through all the rows in my ParentTable (tblPerson) and on each row, search it's ChildTables (tblAddress) related rows for the correct value.
Is there anyway to filter a parent table based on its childs tables values.
Thanks again
Ger
Re: Search Related Tables
I think I may have misunderstood your original question. If you have an Address property, like City, then you can get all the child records with that City value and then call the GetParentRow method of each to get the corresponding Person record, e.g.
vb Code:
Dim addressRows As DataRow() = addressTable.Select(String.Format("City = '{0}'", someCity))
Dim upperBound As Integer = addressRows.GetUpperBound(0)
Dim personRows(upperBound) As DataRow
For index As Integer = 0 To upperBound Step 1
personRows(index) = addressRows(index).GetParentRow(addressPersonRelation)
Next index
Note that the addressPersonRelation refers to a DataRelation in the same DataSet as the two tables that relates them.
Re: [RESOLVED] Search Related Tables
Thanks jmcilhinney,
That should do the trick nicely.
Ger