Hello,

I have a 1 table with a list of departments, and another table with a list of employees who work in those departments.

What I want to do is select a department from a combo box, and display all the employees who work in that department in a list box.

I am using a dataset and created the data relationship between the 2 tables. My code is as follows:

Code:
OleDbCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Employee";
da.SelectCommand = cmd;
da.FillSchema(ds,SchemaType.Source,"Employee");
da.Fill(ds,"Employee");

cmd.CommandText = "SELECT * FROM Department";
da.SelectCommand = cmd;
da.FillSchema(ds,SchemaType.Source,"Department");
da.Fill(ds,"Department");

//Create the relationship for the employee and department tables
DataColumn parentColumn = ds.Tables["Department"].Columns["DepartmentCode"];
DataColumn childColumn = ds.Tables["Employee"].Columns["DepartmentID"];

ds.Relations.Clear();
DataRelation drEmployees = new DataRelation("EmployeeDetails",parentColumn,childColumn);
ds.Relations.Add(drEmployees);

//Use a for loop to add all the employees into a list box - have problem with this part
foreach employee in departments
Add to the list box
Many thanks in advance,

Steve