Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# create report programmatically

I want to create a report, using either Crystal reports or RDLC, doesn't really matter which. I can get all the data sources together as a series of dynamically generated textboxes etc, but how do I add that to a report?

Eg I want customer name and all of their ordered items in a report. Now I can get all of the information in an array... how would I then place that into a Crystal Report?

Any good introductions that cover non-wizards for Crystal Reports would be amazing.

like image 852
David Archer Avatar asked Feb 18 '10 14:02

David Archer


1 Answers

Every datasource of your report has a name (menu report->datasources, It can be not exact because my vs is not in English).

Supose that one of your datasources name is prj_folder_classSample, and classSample is a class of your project. Then you need to add a List to the report.

Let's do it.

List<classSanple> lst = new List<classSample>
lst.Add(...) //Add various instances of classSample
BindingSource thisIsABindingSource = new BindingSource();
thisIsABindingSource.DataSource = lst;
reportDataSource rds = new ReportDataSource("prj_folder_classSample", thisIsABindingSource);

ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.EnableExternalImages = true;
ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.Folder.reportName.rdlc";
ReportViewer1.LocalReport.DataSources.Add(rds)

I do it in this way. Hope It helps you.

like image 153
Jonathan Avatar answered Sep 28 '22 23:09

Jonathan