设置多个对象作为Crystal报表的数据源 [英] Set multiple objects as datasource of a crystal report

查看:215
本文介绍了设置多个对象作为Crystal报表的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使我的C#Windows应用程序中的水晶报表,关键是我想用.NET对象为我的报告数据源,我发现它的样本code如下的网络,并利用它们和正常工作:

I wanna make a crystal report in my c# windows application, the point is I want to use .net objects as my report datasource, I found its sample code as below in internet and use them and it works fine:

        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;

不过,我想送额外的对象,例如学校的信息,这些重复的信息,但是我无法发送这样额外的对象,是没有办法,我可以给多个对象的水晶报表的任何解决方案?当然,我知道我可以使用多个数据表和数据集中Crystal报表数据源,但在这里我只想使用对象和IEnumerables为水晶报表的数据源。

But I want to send extra object for example school information for these repeated information, but I can't send this extra object, is there any solution that I can send multiple objects to the crystal report? Of course I know that I can use multiple datatable and dataset for a crystal report datasource but here I just want to use objects and IEnumerables as datasource of a crystal report.

推荐答案

我不知道是肯定的,它是太晚或根本不。

I don't know for sure that it's too late or not.

如果您有许多数据源,如 1.EmployeeClass 2.EmpployeeSkillClass

if you have many datasource such as 1.EmployeeClass 2.EmpployeeSkillClass

执行以下操作:

      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的瞬间:

//Create instant of ReportDocument :

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

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

//Set datasource to each table. make sure that index of each table is collect

//(在调试模式下运行,以发现表[0]型员工或EmployeeSkill图)

//(run on debug mode to find that tables[0] map with type Employee or EmployeeSkill)

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

        crystalReportViewer1.ReportSource = report;

//完成!!

//Finish!!

这篇关于设置多个对象作为Crystal报表的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆