Crystal Report Using IEnumerable Collection Data Source

[T]here are reasons why i write this crystal report tutorial using IEnumerable data source. First, using IEnumerable we can set data for the report without database in an easy way. Second, we can also using IEnumerable to work with data from database.

Crystal Report IEnumerable

Aside from that, IEnumerable is widely used to store data as in Entity Framework or if you ever create repository using ADO.NET and write raw query there, you should get what i’m talking about.

Creating Report

We will need windows form application to make it working, before you go to next steps, create this type of project first.

If you have installed Crystal Report you will see on the Toolbox a CrystalReportViewer component under Reporting node. Drag and drop it into your form.
1. Add Crystal Report Viewer

Your form now should looks like this
2. Form Design

Model, we need a model to hold the value of something we need to display in the report. In this case i create Book model. For simplicity there are only 4 fields.

After creating the model, you need to build the project

Next add new item which is Crystal Report itself, name it BookReport
3. Add Report

On the pop up dialog choose Using the Report Wizard and Standard
4. Wizard 1

On next window select Project Data – .NET Objects – BookCrystalReport.Book (class model we created before) and mark it as selected tables.
5. Wizard 2

Last, select all fields and click Finish.
6. Wizard 3

Open your BookReport, it looks like this
7. Report Design

Now it is time to fill the report with data. Again, for simplicity i use in memory data but if you know repository pattern that its return value is list of an object you will have no problem to use it with database.

On the code behind of the form modify the constructor as below code.

Run the program and if you have error like below image you only need a little modification.
8. FileNotFound

Open your App.config and modify

Run the program again, this should be your prize
9. Final Report

Facebook Comments
 

Agung Setiawan

Agung Setiawan adalah software engineer di BukaLapak.com, penulis sekaligus pecinta sastra, dan pembaca buku

 
Halo, perkenalkan saya Agung Setiawan.
Saya Software Engineer di BukaLapak.
Simak pemikian saya soal dunia Software Engineering via Twitter di @agungsetiawanmu dan facebook
Blog ini saya update seminggu sekali jadi sering-sering saja mampir
Mau belajar Vim bareng saya?
Belajar ngoding dari nol menggunakan PHP

Leave a Reply

Your email address will not be published. Required fields are marked *