开发者

How to load rdlc and datasource dynamically in ASP.net reportviwer?

I am trying to load the report on the report viewer of ASP.net web application. The thing is that I have two project , class library and web application. In the web application I have .edmx and wcf Data service ( that referring the edmx). Inside the class library I have referencing the service. And I have created one class (Company) which i have written linq query. Finally I have created rdlc report in web application and use the company class as object to get all fields to design the开发者_JAVA技巧 report. This all are perfect and working well. Now what I have problem is that when I tried to load the report dynamically on button click then I got "An error has occurred during report processing.Dataset1" the code I have used is as below:

protected void CompanyReport_Click(object sender, EventArgs e)
        { 
          ReportViewer1.LocalReport.ReportPath = @"c:\..\..\..\..\..\..\..\Reports\CompanyReport.rdlc";
          ReportDataSource ds = new ReportDataSource();
            ds.Name = "Dataset1";
            ReportViewer1.LocalReport.DataSources.Add(ds);

        }


It's possible that the user account your web server is running under does not have access to the path of your report. Besides, the path should probably be relative rather than absolute, because otherwise you will have to change the path when you deploy to your hosted web server. Switching back and forth could become tiresome.

One thing that I noticed in your example is that you are creating the ReportDataSource and assigning a name, but not assigning the datasource. That could be part of the problem.

Try something like this and make sure the theDataSet is an instance of your datasource and that the type of theDataSet matches the type specified for Dataset1 in your report definition.

ReportDataSource ds = new ReportDataSource("Dataset1", theDataSet);

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜