This is a migrated thread and some comments may be shown as answers.

Subreport parameterized query

3 Answers 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sean Beaulac
Top achievements
Rank 1
Sean Beaulac asked on 29 Jul 2009, 07:34 PM
I followed the video tutorial on creating parameterized queries for reports but i'm having trouble replicating it for SubReports. 
The code for the subreport:
            get { return (int)sqlDataAdapter1.SelectCommand.Parameters["@WorkOrderItem"].Value; }
            set { sqlDataAdapter1.SelectCommand.Parameters["@WorkOrderItem"].Value = value; }

the code from the .aspx page:

            Reports.SubReports.WOTechnicianDetails subReport = new Reports.SubReports.WOTechnicianDetails();
            subReport.FK_WorkOrderParam1 = int.Parse(this.Id.ToString());

when I do it this way, the subreport gets the value I want, but it still only loads the default that I put in for the Sql Data Adapter under parameters.  Am I missing a place I need to refresh the report?  Any help is appreciated.

Thanks   



3 Answers, 1 is accepted

Sort by
0
Sean Beaulac
Top achievements
Rank 1
answered on 30 Jul 2009, 03:40 PM
I got it to work without using any of the code above.  After searching through the forums I found that you can reference the parameters from master report to subreport and set the value that way. 
0
Spiros
Top achievements
Rank 1
answered on 30 Jul 2009, 06:34 PM
I'm having a few issues passing the parameter Value.
My sub report  has a sqldataAdapter and needs a parameter that is on the main report.
The Value doesn't seem to come over.

Any ideas?

Spiros
0
Sean Beaulac
Top achievements
Rank 1
answered on 30 Jul 2009, 07:20 PM
Just to make sure, on the main report where you have your sub report, go to your sub report properties and make sure the parameter is being referenced to a value on the main report. 

On the page where the report viewer:

            Telerik.Reporting.SubReport subreportItem = rpt.Items.Find("subReport2", true)[0] as Telerik.Reporting.SubReport;
            subreportItem.ReportSource.ReportParameters["Parameter1"].Value = "the value you want";

On the subreport in NeedDataSource

            Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
            this.sqlDataAdapter1.SelectCommand.Parameters["@WorkOrderItem"].Value = this.ReportParameters[0].Value;
            report.DataSource = this.sqlDataAdapter1;

Also, under InitializeComponent() make sure to set the datasource = null.  It forced the subreport to fire NeedDataSource. 

I found all of this in different places and pieced together what I could and it work.  Hope this helps. 



Tags
General Discussions
Asked by
Sean Beaulac
Top achievements
Rank 1
Answers by
Sean Beaulac
Top achievements
Rank 1
Spiros
Top achievements
Rank 1
Share this question
or