I'm using the following code trying to SetParametr :
var report = new ReportParameter[1];
report[0] = new ReportParameter("MyName", "Raha");
var reportDataSource1 = new ReportDataSource { Name = "WpfApplication17_User", Value = _users };
_reportViewer.LocalReport.DataSources.Add(reportDataSource1);
_reportViewer.ServerReport.SetParameters(report);
_reportViewer.LocalReport.ReportPath = "../../Report1.rdlc";
_reportViewer.RefreshReport();
error : The source of the report definition has not been specified
Why wrong?
I've created a report parameter , Parameter name is 'MyName'
UPDATE :
I'm using the following code :
//var report = new ReportParameter[1];
//report[0] = new ReportParameter("MyName", "Raha");
var reportDataSource1 = new ReportDataSource { Name = "WpfApplication17_User", Value = _users };
string exeFolder = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
_reportViewer.LocalReport.ReportPath =exeFolder + @"\Reports\Report1.rdlc";
_reportViewer.LocalReport.DataSources.Add(reportDataSource1);
//_reportViewer.ServerReport.SetParameters(report);
_reportViewer.RefreshReport();
data displayed in Report.
but , I'm using the following code :
var report = new ReportParameter[1];
report[0] = new ReportParameter("MyName", "Raha");
var reportDataSource1 = new ReportDataSource { Name = "WpfApplication17_User", Value = _users };
string exeFolder = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
_reportViewer.LocalReport.ReportPath = exeFolder + @"\Reports\Report1.rdlc";
_reportViewer.LocalReport.DataSources.Add(reportDataSource1);
_reportViewer.ServerReport.SetParameters(report);//error
_reportViewer.RefreshReport();
error as : The source of the report definition has not been specified
You should change from:
To:
I found myself stuck with the same error, and the reason is actually quite simple: the Report Definition must be set in the first place, before the parameters. This way, the
LocalReport
can check if they are really mandatory and eventually throw an exception.The code below should work:
I had the same problem today, in my case the reason "copy-paste" issue. Just replacing ServerReport with LocalReport in the code below solved the problem. Change
to
The error is not related to your parameter. The error is related to the
ReportPath
. See this other SO question regarding setting the report path. Are you sure the relative path you have specified is correct when your application is running. Is that path relative to your source code? If you want to see where it is looking for the file then you can add some code to resolve that relative path (Path.GetFullPath) and see where it is pointing. Make sure yourrdlc
file is in that folder.Edit:
Based on your updated question and verifying that the report is actually being found. I looked in more detail at your code. You are setting the parameters for the
ServerReport
, but you are loading the report in theLocalReport
. Trying setting the parameters in theLocalReport
.It is possible that your report is an Embedded Resource and thus when you try to set a parameter with
_reportViewer.ServerReport.SetParameters(report);//error
your report definition has not yet been loaded.Therefore if your report is an Embedded Resource then you need to call
report.LoadReportDefinition(stream); // Get report definition
before you set your report parameters.i.e: The below returns a PDF byte array from a LocalReport
Hope this may help others with this similar error.
Put ReportParameter after the
here you write your ReportParameter