i've got an error when render report. am stuck here, please help me..
error like :

Microsoft.Reporting.WinForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: One or more parameters required to run the report have not been specified.

my code is :

private void RenderReport()
        {
            LocalReport localReport = new LocalReport();
            localReport.ReportPath = PemFormatHelper.GetReportFile("test.rdlc");
            
            DataAccess.SPHPDa sphpDa = new DataAccess.SPHPDa();
            dtHdrSource = sphpDa.ReportHdrSPHP(sphp.SphpId, ConnectionSession.LoginID, sphp.SphpType);


            List<ReportParameter> paramCollection = new List<ReportParameter>();
            paramCollection.Add(new ReportParameter("NamaKanwil", dtHdrSource.Rows[0]["NM_KANWIL"].ToString()));
            paramCollection.Add(new ReportParameter("NamaKPP", dtHdrSource.Rows[0]["NM_KPP"].ToString()));
            paramCollection.Add(new ReportParameter("AlamatKPP", dtHdrSource.Rows[0]["ALAMAT_KPP"].ToString()));
            paramCollection.Add(new ReportParameter("KotaKPP", dtHdrSource.Rows[0]["KOTA_KPP"].ToString()));
            paramCollection.Add(new ReportParameter("KdPosKPP", dtHdrSource.Rows[0]["KD_POS_KPP"].ToString()));
            paramCollection.Add(new ReportParameter("KTKPos", dtHdrSource.Rows[0]["KTK_POS"].ToString()));
            paramCollection.Add(new ReportParameter("TelpKpp", dtHdrSource.Rows[0]["TELP_KPP"].ToString()));
            paramCollection.Add(new ReportParameter("FaxKpp", dtHdrSource.Rows[0]["FAX_KPP"].ToString()));
            paramCollection.Add(new ReportParameter("CompCtr", dtHdrSource.Rows[0]["COMP_CTR"].ToString()));
            paramCollection.Add(new ReportParameter("SMSCenter", dtHdrSource.Rows[0]["SMS"].ToString()));
            paramCollection.Add(new ReportParameter("TollFree", dtHdrSource.Rows[0]["TOLL_FREE"].ToString()));

            ReportDataSource dtSourceHeader = new ReportDataSource("DataReport_Sphp", dtHdrSource); 

            localReport.DataSources.Add(dtSourceHeader);

            string reportType = "PDF";
            string mimeType;
            string encoding;
            string fileNameExtension;

            string deviceInfo =
            "<DeviceInfo>" +
            "  <OutputFormat>PDF</OutputFormat>" +
            "  <PageWidth>8.5in</PageWidth>" +
            "  <PageHeight>11in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>1in</MarginLeft>" +
            "  <MarginRight>1in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;
                 
            //Render the report
            
           localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
}

Dani AI

Generated

the exception is exactly what suspected: your parameters never reached the report when you called LocalReport.Render. In a LocalReport-only workflow you must set every required report parameter on the same LocalReport instance before rendering; otherwise the processor throws “parameters not specified.” Use LocalReport.SetParameters(...) and make sure the parameter names match those defined in the RDLC. (video2.skills-academy.com)

Two quick checks usually resolve this error:

  • Verify you are adding all the data sources your RDLC expects and that each ReportDataSource.Name matches the name defined in the report. The constructor docs call out that the name must be the one specified in the report definition. (learn.microsoft.com)
  • After loading the RDLC, inspect the required parameters and confirm you provide non-null values for any that are not marked Nullable. You can query the report for its parameters and their metadata, including Nullable and PromptUser. (video2.skills-academy.com)

Minimal LocalReport-only pattern (no viewer control):

using Microsoft.Reporting.WinForms;

var rpt = new LocalReport { ReportPath = "MyReport.rdlc" };
rpt.DataSources.Add(new ReportDataSource("HeaderDs", headerTable));
rpt.DataSources.Add(new ReportDataSource("DetailDs", detailTable));

// Inspect what the RDLC expects
var defined = rpt.GetParameters().Select(p => p.Name).ToArray();  // helpful for debugging

// Supply every required parameter
rpt.SetParameters(new[] {
    new ReportParameter("CompanyName", companyName ?? string.Empty),
    new ReportParameter("ReportDate", reportDate.ToString("yyyy-MM-dd"))
});

// Render straight to PDF
string mime, enc, ext; string[] ids; Warning[] warns;
byte[] pdf = rpt.Render("PDF", null, out mime, out enc, out ext, out ids, out warns);

Note: switching to ReportViewer worked in your follow-up because you called ReportViewer.LocalReport.SetParameters(...) and added both data sources to that same LocalReport instance behind the control. You can do the same entirely in code without the visual control; LocalReport is designed for this scenario. (learn.microsoft.com)

Recommended Answers

All 2 Replies

I can't be 100% sure, as I'm not sure where you're getting your data, but you don't seem to be doing anything with the "paramCollection" data structure. Shouldn't that be set somewhere in one of the parameters that is going into the report?

thanx for reply, the code is run away now. :)
my mistake is, localreport going to be render.
when i use reportviewer to render it normaly work.
this my code,.... i hope anyone have this same problem can solve that.

private void RenderReport()
{
	LocalReport localReport = new LocalReport();
	//localReport.ReportPath = PemFormatHelper.GetReportFile("SPHPView.rdlc");

	//header
	DataAccess.SPHPDa sphpDa = new DataAccess.SPHPDa();
	dtHdrSource = sphpDa.ReportHdrSPHP(sphp.SphpId, ConnectionSession.LoginID, sphp.SphpType);

	ReportViewer ReportViewer = new ReportViewer() ;

	List<ReportParameter> paramCollection = new List<ReportParameter>();
	paramCollection.Add(new ReportParameter("NamaKanwil", dtHdrSource.Rows[0]["NM_KANWIL"].ToString()));
	paramCollection.Add(new ReportParameter("NamaKPP", dtHdrSource.Rows[0]["NM_KPP"].ToString()));
	paramCollection.Add(new ReportParameter("AlamatKPP", dtHdrSource.Rows[0]["ALAMAT_KPP"].ToString()));
	paramCollection.Add(new ReportParameter("KotaKPP", dtHdrSource.Rows[0]["KOTA_KPP"].ToString()));
	paramCollection.Add(new ReportParameter("KdPosKPP", dtHdrSource.Rows[0]["KD_POS_KPP"].ToString()));
	paramCollection.Add(new ReportParameter("KTKPos", dtHdrSource.Rows[0]["KTK_POS"].ToString()));
	paramCollection.Add(new ReportParameter("TelpKpp", dtHdrSource.Rows[0]["TELP_KPP"].ToString()));
	paramCollection.Add(new ReportParameter("FaxKpp", dtHdrSource.Rows[0]["FAX_KPP"].ToString()));
	paramCollection.Add(new ReportParameter("CompCtr", dtHdrSource.Rows[0]["COMP_CTR"].ToString()));
	paramCollection.Add(new ReportParameter("SMSCenter", dtHdrSource.Rows[0]["SMS"].ToString()));
	paramCollection.Add(new ReportParameter("TollFree", dtHdrSource.Rows[0]["TOLL_FREE"].ToString()));

	ReportDataSource dtSourceHeader = new ReportDataSource("DataReport_Sphp", dtHdrSource);
	//localReport.DataSources.Add(dtSourceHeader);

	dtDtlSource = sphpDa.ReportDtlSPHP(sphp.SphpId, ConnectionSession.LoginID, sphp.SphpType);
	ReportDataSource dtSourceDetail = new ReportDataSource("DataReport_dtSphpDtlTbl", dtDtlSource);

	ReportViewer.LocalReport.DataSources.Clear();
	ReportViewer.LocalReport.ReportPath = PemFormatHelper.GetReportFile("SPHPView.rdlc");
	ReportViewer.LocalReport.DataSources.Add(dtSourceHeader);
	ReportViewer.LocalReport.DataSources.Add(dtSourceDetail);
	ReportViewer.LocalReport.SetParameters(paramCollection);
	ReportViewer.RefreshReport();

	Export(ReportViewer.LocalReport);  

 
}

private void Export(LocalReport report)
{

	string deviceInfo =
	  "<DeviceInfo>" +
	  "  <OutputFormat>EMF</OutputFormat>" +
	  "  <PageWidth>8.5in</PageWidth>" +
	  "  <PageHeight>11in</PageHeight>" +
	  "  <MarginTop>0in</MarginTop>" +
	  "  <MarginLeft>0in</MarginLeft>" +
	  "  <MarginRight>0in</MarginRight>" +
	  "  <MarginBottom>0in</MarginBottom>" +
	  "</DeviceInfo>";

	Warning[] warnings;
	m_streams = new List<Stream>();

	report.Render("Image", deviceInfo, CreateStream, out warnings);
	
	foreach (Stream stream in m_streams)
		stream.Position = 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.