Creating local report using MS Reporting Services

Microsoft reporting services provide the way to represent data in the form of reports in easy manner. It’s a powerful tool, we can generate complex reports using it.   We can create reports by creating Server Reports Project in visual studio  and publish them to server. We can also create local report for ASP.NET using the same mechanism. Here i want to show you how can we achieve this.

Before going further check if your system got Reporting Services components installed. Create a Server Reports project (here i am using VS2005) by following the steps in this link. In this example i am assuming that your report consumes data returned from Stored Procedure and your SP takes some parameters. The report files created by this project will have .rdl extension and these files are XML files so you can easily change them using any notepad.

Now copy your final report file(.rdl) to ASP.NET application and change the file extension to .rdlc. Now open the report file using any text editor like notepad then remove the parameters tags if your reports requires any parameters.

How to remove parameter tags:

<ReportParameters></ReportParameters> and <QueryParameters></QueryParameters> section of the XML represents the parameters required by your report. So delete these tags and content inside these tags and save the file. Now your report is ready to use in your ASP.NET application.

Add report viewer control to your webpage. Below code shows, code required to use SSRS reports as local report.

Default.aspx:

<rsweb:ReportViewer ID="rptViewer" runat="server" Width="100%" ShowBackButton="false" ShowExportControls="true"
ShowFindControls="true" ShowPageNavigationControls="true" ShowRefreshButton="false" ShowPrintButton="false"
ShowParameterPrompts="false" ShowZoomControl="false" Visible="false">
<LocalReport>

</LocalReport>
</rsweb:ReportViewer>

Default.aspx.cs:

DataTable dt = GetReportData(param1);
String path = &quot;~/Reports/YourReport.rdlc&quot;;
BindDataToReport(dt, path);
private void BindDataToReport(DataTable reportDataTable,String reportPath)
{

    if (reportDataTable != null &amp;&amp; reportDataTable.Rows.Count &gt; 0)
    {
        rptViewer.Visible = true;
        rptViewer.LocalReport.ReportPath = string.Empty;
        ReportDataSource rptDataSource = new ReportDataSource(&quot;ReportDataSource&quot;, reportDataTable);
        rptViewer.LocalReport.DataSources.Clear();
        rptViewer.Reset();
        rptViewer.LocalReport.ReportPath = Server.MapPath(reportPath);
        rptViewer.LocalReport.DataSources.Add(rptDataSource);
        rptViewer.LocalReport.Refresh();
    }
    else
    {

       //else part here
    }
}

Note:

In the above example i created report using VS2005 and used it as local report in the project created by .NET3.5(VS2008) because the local reports in VS2010 uses SSRS 2008 schema while VS2008 uses SSRS 2005 schema. SSRS 2008 introduces tablix data region concept which is the combination of matrix,table and list. This is not available in SSRS 2005. So take care while using reports as local report.

I hope this post helpful to you. Happy coding Happy

3 thoughts on “Creating local report using MS Reporting Services

  1. Thanks a lot for this sample – it took a while to find it but it answered how to convert to .rdlc and handling parameters

    About parameters though how are they handled now, especially if before with SSRS they had settings, validation. dropdown, etc especially when you have multiple reports

    This book is a great resource for CREATING a new report from scratch: Learning SQL Server Reporting Services 2012 By Jayaram Krishnaswamy and his websites/blogs which was a saviour along with the link below.

    This CODEPLEX site is also one of the best sites I have found. http://reportviewer.codeplex.com/

    I was given the task of migrating our reports (*.rdl) off our Report Server and onto the same server where the web app is running ( using *.rdlc )

    (1) I havent been able to find anything explaining how to access and reference multiple reports without hardcoding them as shown here:
    http://forums.asp.net/t/1472608.aspx
    Other websites and references just illustrate a single record or worse created a new report.

    (2) Report parameters: Can it dynamically code for the parms or do we have to code for each report individually as indicated on the same website mentioned above.

    Sincerely

    George Lewycky
    New York City
    George.lewycky@nyct.com

    Other useful link I found are:
    http://www.gotreportviewer.com/
    http://blog.jsmoot.com/2013/10/thinking-of-using-microsoft-reports.html

    Like

Leave a comment