I'm getting “The report definition for report 'xxxx.rdlc' has not been specified” in my RDLC report

前端 未结 6 1800
野的像风
野的像风 2020-12-02 02:23

I\'ve created an rdlc report. I have a reportViewer on my form. When I try to load the report I get : \"The report definition for report \'xxxx.rdlc\' has not been specifie

6条回答
  •  -上瘾入骨i
    2020-12-02 02:34

    Exactly like what you said because that rdlc requires some sort of a dataSource :) It is a tricky issue in Report viewer and to solve it I wrote a method that will bind the report direct from Datatable:

    private void GenerateReportDirect(ReportViewer reportViewer, string datasource, DataTable dt, string reportpath)
    {
        reportViewer.LocalReport.ReportPath = reportpath;
        ReportDataSource repds = new ReportDataSource(datasource, dt);
        reportViewer.LocalReport.DataSources.Clear();
        reportViewer.LocalReport.DataSources.Add(repds);
        reportViewer.LocalReport.Refresh();
    }
    

    and to implement this method you have to specify putting the string of dataset table adapter just a name but our report will take the data to bind from the data table (we will cheat on our report viewer :) )

    private void BindReport(DataTable dt)
        {
                string reportPath = Server.MapPath("StudentBus.rdlc");
                GenerateReportDirect(ReportViewer1, "StudentDataSet_usp_RPT_StudentBus", dt, reportPath);
        }
    

    I hope this will help :) .

提交回复
热议问题