none
VS2008 Subreport with SQL Parameter RRS feed

  • Question

  • Greetings All! I have searched all over the web for a solution to this and I guess I'm just missing something or doing something wrong. I have found a lot of responses to similar questions, but none seem to quite hit the nail on the head.

    I'm using VS2008 and I have created a simple Local Report that is embedded on a ASPX page in a ReportViewer object. The report is bound to a TableAdapter data source that pulls data from a SQL Server Stored Procedure with 1 Parameter (@LOGID).

    I have configured the Datasource in the the ReportViewer using the "ObjectDataSource->Configure Data Source" option to map the Stored Proceduer parameter @LOGID to a control on the ASPX page which I set programatically when the page loads.

    This works fine for the main report. The problem has come in since I embedded a Subreport object in the main report. The subreport is intended to show a list of items related to the record in the main report.

    The subreport is also based on a TableAdapter object (different one) which retrieves data from SQL via a Stored Procedure with 1 Parameter (@LOGID - same as the main report). However, in the Subreport control configuration, there is no way (that I can see) to map the Stored Procedure input parameter to any control or report parameter. I have read many posts which say "just map a parameter from the main report to the subreport paramter!" That's fine, and I can do that, but now how do I get the Subreport Parameter mapped to the input parameter for the SQL Stored Procedure. It doesn't seem to be automatic.

    I have also tried to reference the subreport in my ASPX code page to programatically set the parameter, but I have not been able to find the object reference to the parameter (so far).

    I created the subreport (seperate RDLC file) with a single table object. I added the Table Adapter object as a data source from "Report->Data Sources" where I selected the Table Adapter and clicked "Add to Report". Then, in "Properties" for the Table object in the report designer, I set the DataSetName to the Data Source I added to the report.

    Every time I compile and run the project, the main report queries and runs fine, but the SubReport keeps giving me "Error: Subreport could not be shown." in the window. I'm sure this is becuase the SQL Stored Procedure isn't getting the parameter value it needs.

    I am not using Crystal Reports. This is simply the basic ReportViewer and Subreport tools included in VS2008.
    Any suggestions are greatly appreciated.
    Thursday, January 27, 2011 3:21 PM

All replies

  • Check out the samples in http://code.msdn.microsoft.com/reportviewer. This is a VS2010 solution, but in principle you should be able to use the code there to do the same thing. There's a sample called "SupplyingData" that shows how to hook up drillthrough reports and subreports in code.
    Cephas Lin This posting is provided "AS IS" with no warranties.
    Friday, January 28, 2011 11:33 PM
    Moderator