I\'m using the following code trying to SetParametr :
var report = new ReportParameter[1];
report[0] = new ReportParameter(\"MyName\", \"Raha\");
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
public byte[] ProcessReportToPDFBytes(List rds, Stream stream, string fileName, string outputType, SqlParameter[] rptParameters)
{
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
using (LocalReport report = new LocalReport())
{
// Setup the report viewer object and get the array of bytes
report.EnableHyperlinks = true;
report.EnableExternalImages = true;
report.SetBasePermissionsForSandboxAppDomain(new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted));
report.LoadReportDefinition(stream); // Get report definition
// **** Set the Report Parameters AFTER the LoadReportDefinition ****
if (rptParameters != null)
{
foreach (SqlParameter param in rptParameters)
{
report.SetParameters(new ReportParameter(param.ParameterName, param.Value == null ? "" : param.Value.ToString(), false));
}
}
foreach (ReportDataSource rds1 in rds)
{
report.DataSources.Add(rds1); // Add datasource here
}
// Render the PDF from the local report
return report.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
}
}
Hope this may help others with this similar error.