Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using (LocalReport reportEngine = reportViewer1.LocalReport)                
                {       this.Instrument_ReadingsTableAdapter.Fill(this.LiveDataSetFromActualDB.Instrument_Readings);                 
                    reportEngine.ReportPath = Application.StartupPath + "\\Report1.rdlc";
                    //reportEngine.ReportPath = Application.StartupPath + "\\Report2.rdlc";
                    
                    // -- NEW CODE ADDED HERE
                    //ReportDataSource rds = new ReportDataSource();
                    //rds.Name = "Datasettest";
                    //rds

                    var dt_min = this.Instrument_ReadingsTableAdapter.Min();
                    var dt_max = this.Instrument_ReadingsTableAdapter.Max();

                    if (!dt_min.HasValue || !dt_max.HasValue)
                    {
                        return;
                    }

                    var diff = (dt_max.Value - dt_min.Value).TotalMinutes;

                    this.reportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc";

                    ReportParameter rp = new ReportParameter("Time_Span", diff.ToString());
                    reportEngine.SetParameters(new ReportParameter[] { rp });
                    this.reportViewer1.RefreshReport();


What I have tried:

I recieve an error
"Microsoft.reporting.WinForms.LocalReport.InternalGetReportParameters(CatalogItemContextBase reportContext, NameValueCollection userSpecifiedValues, ParameterInfoCollection baseLineParameters, DatasourceCredentialsCollection credentials, ReportRuntimeSetup reportRuntimeSetup at Microsoft.Reporting.Winforms.LocalReport.SetParameters(IEnumerable1 parameters)
at
Live_AM_Report.Form1.Form1_Load(Object sender, EventArgs e)
... line 255 , which = reportEngine.SetParameters(new ReportParameter[] { rp });

On the design side of the rdlc

I have added a parameter called Timespan in the "Report data"
I also added the textbox that refers to the parameter, now its a simple case of setting the value in that parameter, and the textbox should call it.
The Textbox's Value field = [@Time_Span] (The parameter i added)

I have struggled with this for a few days now, and its really frustrating, any help would be greatly appreciated.
Posted
Updated 14-Jul-16 22:21pm
Comments
Richard Deeming 14-Jul-16 9:59am    
What you've given us is part of the stack trace of the error. You've missed out the important part - the actual error message.

Click "Improve question" and update your question with the full details of the exception.

Also, you say you've created a parameter called "Timespan", but your code is trying to set a parameter called "Time_Span" - is that a typo in your question?

1 solution

To Add Parameter to RDLC report.
1. Open report in Visual Studio.
2. Press CRL + ALT + D
3. "Report Data" tab gets open.
4. Select "Parameter" and right click to add parameter.

In Set parameter
C#
ReportParameter[] rptParams = new ReportParameter[]
            {
                new ReportParameter("param1",txtParam1.Text),
                new ReportParameter("param2",txtParam2.Text)
};
rptInvoiceTC.LocalReport.SetParameters(rptParams);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900