I am creating a site using ASP.net in Visual Studio 2010 and am having trouble with the Report Viewer control. I am trying to use one report viewer control and set the report name and data sets dynamically. I do not have an SSRS server available so all of this is internal to the application. I've tried two approaches, first on the ASP side:
<% if (true)
{ %>
<rsweb:ReportViewer ID="ReportViewer1" runat="server"
Font-Names="Verdana"
Font-Size="8pt" InteractiveDeviceInfos="(Collection)"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"
Width="538px">
<LocalReport ReportPath="AFR\SimpleTest.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="dsTestInReport"
Name="dsTest" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:SqlDataSource ID="dsTestInReport" runat="server"
ConnectionString="<%$ ConnectionStrings:Survey %>"
SelectCommand="SELECT * FROM [trefQuestionType]">
</asp:SqlDataSource>
<% }
else
{ %>
<rsweb:ReportViewer ID="ReportViewer2" runat="server"
Font-Names="Verdana"
Font-Size="8pt" InteractiveDeviceInfos="(Collection)"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"
Width="538px">
<LocalReport ReportPath="AFR\SimpleTest.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="SqlDataSource1"
Name="dsTest" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Survey %>"
SelectCommand="SELECT * FROM [trefMinistry]"></asp:SqlDataSource>
<%} %>
But all I got was a single report header with no data. If I comment out the If / else, I get two complete reports with data, but with the If / else included, I get nothing. Argh! So I decided to try Code Behind ...
SqlCommand _cmd = new SqlCommand("SELECT * FROM [trefMinistry]", _cn);
SqlDataAdapter _da = new SqlDataAdapter(_cmd);
System.Data.DataTable _tbl = new System.Data.DataTable();
_da.Fill(_tbl);
ReportViewer1.LocalReport.Dispose();
ReportViewer1.LocalReport.ReportPath = @"AFR\SimpleTest.rdlc";
ReportViewer1.LocalReport.DataSources.Add(new
Microsoft.Reporting.WebForms.ReportDataSource("dsTest", _tbl));
When I ran this, I got the error:
"An unexpected error occurred in Report Processing.
Value cannot be null. Parameter name: input"
Any pointers, tips, help or cash would be sincerely appreciated. (Sorry for the length, just trying to be complete.)