我想创建一个报表,使用 Crystal 报表或 RDLC,哪个并不重要。我可以将所有数据源作为一系列动态生成的文本框等放在一起,但如何将其添加到报告中?
例如,我想要一份报告中的客户名称和他们所有订购的商品。现在我可以获取数组中的所有信息...然后如何将其放入 Crystal Report 中?
任何涵盖 Crystal Reports 非向导的好的介绍都将是惊人的。
最佳答案
你report的每一个datasource都有一个名字(菜单report->datasources,可能不准确,因为我的vs不是英文的)。
假设您的其中一个数据源名称是 prj_folder_classSample,classSample 是您项目的一个类。然后您需要向报告中添加一个列表。
让我们开始吧。
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)
我是这样做的。希望对你有帮助。
关于C# 以编程方式创建报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2289165/