1

I have the following two tables:

Employee table:

EmployeeID  
Name

etc.

Project table:

ProjectID  
EmployeeID  
ProjectDescription

Each Employee can manage zero or more projects.

I know how to use the DataSet Designer to add the Employee table as details (multiple bound controls) on Form1 (Windows Form Application):

Dragging the Company database's Employee table (as details) to form creates the following components:

• CompanyDataSet
• employeeBindingSource
• employeeTableAdapter
• tableAdapterManager
• employeeBindingNavigator

  1. How do you add a ListBox to Form1 that displays the ProjectDescription of all the projects the currently displayed Employee manages? What ListBox properties need to be set?

    I believe I will need the following query:

    SELECT Project.ProjectDescription  
    FROM  Project RIGHT JOIN Employee ON Project.EmployeeID = Employee.EmployeeID  
    WHERE EmployeeID = ?  
    

    Parameter would be the employeeIDtextbox.Text

  2. Project records will be created programmatically (OleDbConnection, OleDbCommand) from Form2. What statement is required to update Form1 when it is displayed?

I have searched the web and read pages and pages of Microsoft documentation and have hit a wall...

4

1 回答 1

0

如果您询问如何将 ProjectDescriptions 放入 ListBox,您可以简单地遍历查询返回的记录集并将每个条目添加到列表框

foreach (DataRow r in foo)
{
    projectlistbox.Items.Add(r["ProjectDescription"]);
}

它不优雅,但它有效。我不能保证代码确实如此,但我没有 C# IDE 来测试它。不过,它应该为您指明正确的方向。

Form1在从 输入数据后进行更新Form2,请将代码放入Form1.Activated以检查更新的数据并Form1适当地更改对象。

于 2013-05-22T06:21:50.520 回答