Set multiple objects as datasource of a crystal report

后端 未结 2 778
孤独总比滥情好
孤独总比滥情好 2020-12-11 03:13

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

相关标签:
2条回答
  • 2020-12-11 03:55

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

    Do the following :

          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" });
    

    //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

    //(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!!

    0 讨论(0)
  • 2020-12-11 04:02

    When you do this on Design Mode, it tells you that it isn't supported.

    Maybe with an Xref between datasources...

    0 讨论(0)
提交回复
热议问题