Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
244 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...