使用RDLC的报告无法加载数据集

时间:2014-06-29 16:49:49

标签: c# winforms reporting-services report error-reporting

我正在尝试使用RDLC文件生成报告。我正在关注此链接:

http://www.mindstick.com/Articles/13169999-ef3b-496c-b502-caef973c3bb2/?Using%20ReportViewer%20in%20WinForms%20C

所以我创建一个RDLC文件,导入我的tax对象到这个报告我的tax ubject有这样的结构:

public partial class Tax
    {
        public Tax()
        {
            this.Innovices = new HashSet<Inovice>();
        }
        [DisplayName("شناسه")]
        public int Id { get; set; }
        [DisplayName("عوارض شهرداری")]
        public Nullable<double> MunicipalTax { get; set; }
        [DisplayName("مالیات بر ارزش افزوده")]
        public Nullable<double> AdditionalTax { get; set; }
        [DisplayName("سال مالی")]
        public string Year { get; set; }

        public virtual ICollection<Inovice> Innovices { get; set; }
    }

在这里,您可以看到我的报告的绑定对象:

enter image description here

我以y形式放了一个reportviewer,我在`formload

中编写了这段代码
 private void Form1_Load(object sender, EventArgs e)
        {
            InvoiceRepository.TaxRepository obj = new TaxRepository();
            List<InnoviceDomainClass.Tax> list = obj.GetAll().ToList();

            reportViewer1.LocalReport.DataSources.Clear(); //clear report
            reportViewer1.LocalReport.ReportEmbeddedResource = "Factor169.Report.Report1.rdlc";
                // bind reportviewer with .rdlc

            Microsoft.Reporting.WinForms.ReportDataSource dataset =
                new Microsoft.Reporting.WinForms.ReportDataSource("Dataset1", list); // set the datasource
            reportViewer1.LocalReport.DataSources.Add(dataset);
            dataset.Value = list;

            reportViewer1.LocalReport.Refresh();
            reportViewer1.RefreshReport(); // refresh report
        }`

但执行后的结果是这样的:为什么? enter image description here

1 个答案:

答案 0 :(得分:2)

Microsoft.Reporting.WinForms.ReportDataSource dataset =
            new Microsoft.Reporting.WinForms.ReportDataSource("Dataset1", list); 

应该是 DataSet1

ReportDataSource("DataSet1", list); //The "s"

报告数据源的名称必须与报告中的数据集相同。