【问题标题】:Set multiple objects as datasource of a crystal report将多个对象设置为水晶报表的数据源
【发布时间】:2010-05-26 07:31:22
【问题描述】:

我想在我的 c# windows 应用程序中制作一个水晶报表,重点是我想使用 .net 对象作为我的报表数据源,我在互联网上找到了如下示例代码并使用它们,它工作正常:

        ArrayList Mainlst = new ArrayList();
        Mainlst.Add(new testOBJ { Firstname = "test1", Lastname = "test11" });
        Mainlst.Add(new testOBJ { Firstname = "test2", Lastname = "test21" });
        Mainlst.Add(new testOBJ { Firstname = "test3", Lastname = "test31" });
        Mainlst.Add(new testOBJ { Firstname = "test4", Lastname = "test41" });
        Mainlst.Add(new testOBJ { Firstname = "test5", Lastname = "test51" });
        testCrystalReport rpt = new testCrystalReport ();
        rpt.SetDataSource(Mainlst);
        crystalReportViewer1.ReportSource = rpt;

但是我想为这些重复的信息发送额外的对象,例如学校信息,但我无法发送这个额外的对象,有什么解决方案可以将多个对象发送到水晶报告?当然我知道我可以使用多个数据表和数据集作为水晶报表数据源,但在这里我只想使用对象和 IEnumerables 作为水晶报表的数据源。

【问题讨论】:

    标签: c# .net crystal-reports


    【解决方案1】:

    如果您有很多数据源,例如 1.Employee类 2.员工技能类

    执行以下操作:

          List<EmployeeClass> employeeList = new List<EmployeeClass>();
          employeeList.Add(new EmployeeClass() { EmpNo = "001", EmpName = "Supitchaya" });
    
          List<EmpployeeSkillClass> employeeSkillList = new List<EmpployeeSkillClass>();
          detList.Add(new EmpployeeSkillClass() { EmpNo = "001", Skill="C#" });
          detList.Add(new EmpployeeSkillClass() { EmpNo = "001", Skill="Java" });
    

    //创建ReportDocument的瞬间:

            ReportDocument report = new RptEmployee(); //Crsytal report file
    

    //为每个表设置数据源。确保每个表的索引是收集的

    //(在调试模式下运行以查找表[0]映射为Employee或EmployeeSkill)

            report.Database.Tables[0].SetDataSource(employeeList );
            report.Database.Tables[1].SetDataSource(employeeSkillList );
    
            crystalReportViewer1.ReportSource = report;
    

    //完成!!

    【讨论】:

    • 我想知道你是否知道为什么我的报告是空的
    • @Enzero 我刚看到你的问题。我想你可能有答案。抱歉回复晚了
    【解决方案2】:

    当您在设计模式下执行此操作时,它会告诉您它不受支持。

    可能在数据源之间使用外部参照...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多