I have two tables in a DataSet where the ID field on each is the same. I have a Relation between the two tables. How do I, in C# code, pull the info from Table2 that relates to the info on Table1?
I have tried using a new DataRow and assigning it by using GetChildRow, but for some reason I cannot seem to make it work.
Also, I understand this question may not be that informative, let me know and I will try to provide more clarification.
The answer is different (and significantly easier) if your DataSet is strongly-typed (i.e. generated from a .xsd file). I’ll assume that’s not the case below, but if it is speak up.
For generic DataSet objects, the answer largely depends on what you have hold of to start. If you have simply an ID, then it’s probably simplest to use the ID in a select on the relevant DataTable. This will work for either (or both) tables as it will return an array of DataRows with the information you’re looking for.
If you have a parent DataRow (and it seems likely that you do), then the best method to use depends on the relationship—i.e. which is the parent. If Table1 is your parent and you want to navigate to relevant Table2 child rows, you’re looking for GetChildRow (best to be as specific as you can in telling it which relation to follow). If Table2 is the parent and you’re navigating from a Table1 DataRow to the parent in Table2, you’ll want to use GetParentRow (again, be as specific in identifying the relation as you can—use the relation object if you have it handy).