【问题标题】:DataTables DataRelation Opposite Right Outer JoinDataTables DataRelation Opposite Right Outer Join
【发布时间】:2013-07-12 16:34:52
【问题描述】:

我有三个数据网格视图(Department、Employee、EmployeeNotInDepartment)。我已经根据 DataRelations 填充了 Department 和 Employee 数据网格视图(见下文)。我认为必须有一种明显简单的方法来填充 EmployeeNotInDepartment 数据网格视图。有任何想法吗?我希望我不必使用 linq。

public Form1()
{
        InitializeComponent();

        dtDepartment = FillDepartmentList();
        dtEmployee = FillEmployeeList();
        dsDepartmentEmployees = new DataSet();

        // Add tables to dataset
        dsDepartmentEmployees.Tables.Add(dtDepartment);
        dsDepartmentEmployees.Tables.Add(dtEmployee);

        // Create table relationship
        dsDepartmentEmployees.Relations.Add("DepartEmpRelation", dtDepartment.Columns["DepartmentNumber"], dtEmployee.Columns["DepartmentNumber"],true);

        BindingSource bsDepartment = new BindingSource();
        bsDepartment.DataSource = dsDepartmentEmployees;
        bsDepartment.DataMember = "table1";

        BindingSource bsEmployee = new BindingSource();
        bsEmployee.DataSource = bsDepartment;
        bsEmployee.DataMember = "DepartEmpRelation";

        dataGridView1.DataSource = bsDepartment;
        dataGridView2.DataSource = bsEmployee;

}

【问题讨论】:

  • 有什么理由不使用 linq?它为您管理所有关系。
  • 我知道如何使用 linq 来做到这一点,但我想知道是否有一种明显简单的方法可以使用数据集关系来做到这一点。我找不到关于这种方法的任何文档。

标签: c# datarelation


【解决方案1】:

如果您坚持不使用 LINQ,那么您可以使用 DataView 并在 RowFilter 属性中指定您的过滤器(它可以是您不想显示的逗号分隔的 ID 列表)

This is howDataView 上使用RowFilter

【讨论】:

  • 感谢您的帮助,我想我现在可以使用 linq。
【解决方案2】:

正如@Rwiti 所建议的,您可以使用 DataView 的 RowFilter 属性,您可以定义适当的表达式来过滤掉基于此的行。

查看下面的链接,其中列出了 RowFilter 的各种示例,包括 NOT IN

http://www.csharp-examples.net/dataview-rowfilter/

但是,如果您没有任何理由不使用 Linq(即必须使用 .net 2.0),那就去吧。

【讨论】:

    猜你喜欢
    • 2013-03-10
    • 1970-01-01
    • 2014-01-07
    • 2013-05-02
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2010-10-04
    相关资源
    最近更新 更多