The source of the report definition has not been specified

前端 未结 6 1227
别那么骄傲
别那么骄傲 2020-12-21 12:41

I\'m using the following code trying to SetParametr :

    var report = new ReportParameter[1];
    report[0] = new ReportParameter(\"MyName\", \"Raha\");
            


        
6条回答
  •  清酒与你
    2020-12-21 13:37

    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.

提交回复
热议问题