M
Martin Robins
Ok, so everybody sings the praises of or dishes the DataSet; I use them, but
not nearly enough as I probably should. So, here is my question:
A DataSet can have more than one table, and those tables can be related; so,
how can I loop through all the records in a table and get related values
from the other tables?
For example, lets say that I create a dataset with 3 tables; Accounts,
Status and Controller:
Accounts: Reference, Name, StatusId, ControllerId
Status: Id, Text
Controller: Id, Name
I set up a relationship between the tables where Accounts.StatusId=Status.Id
and Accounts.ControllerId=Controller.Id
Now, how do I loop through the rows of Accounts, pulling the correct status
and controller from the related tables?
foreach(DataRow row in ds.Tables["Accounts"].Rows) {
Console.WriteLine(row["Reference"]); // Display the account
reference
Console.WriteLine( ???????????? ); // Display the controller
}
I know that this can be done as I have seen similar examples (though
normally working the other way around - Select the controller and run
through the accounts for example), but I have developed a mental block
(instead of software!) on how to do it.
Cheers.
not nearly enough as I probably should. So, here is my question:
A DataSet can have more than one table, and those tables can be related; so,
how can I loop through all the records in a table and get related values
from the other tables?
For example, lets say that I create a dataset with 3 tables; Accounts,
Status and Controller:
Accounts: Reference, Name, StatusId, ControllerId
Status: Id, Text
Controller: Id, Name
I set up a relationship between the tables where Accounts.StatusId=Status.Id
and Accounts.ControllerId=Controller.Id
Now, how do I loop through the rows of Accounts, pulling the correct status
and controller from the related tables?
foreach(DataRow row in ds.Tables["Accounts"].Rows) {
Console.WriteLine(row["Reference"]); // Display the account
reference
Console.WriteLine( ???????????? ); // Display the controller
}
I know that this can be done as I have seen similar examples (though
normally working the other way around - Select the controller and run
through the accounts for example), but I have developed a mental block
(instead of software!) on how to do it.
Cheers.