Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,
I want to add sub report in crystal Report. I have added the sub report in the design part but I am getting exception missing parameter value. I dnt how to write code behind in existing code .
Please help me in writing code behind for sub report.

My code behind for main crystal report is :-

CREngine.ReportDocument reportDoc = new CREngine.ReportDocument();
try
{
ConnectionInfo conInfo = new ConnectionInfo();
if (conn.DataSource.Equals("72.18.131.163,1533"))
{
conInfo.ServerName = "72.18.131.163,1533";
conInfo.DatabaseName = "DedStaffApproval";
conInfo.UserID = "prabodh";
conInfo.Password = "prabodh$123";
}
else
{
conInfo.DatabaseName = "DedStaffApproval";
conInfo.IntegratedSecurity = true;
conInfo.ServerName = "SAHDEV";
}
//conInfo.ServerName = "SAHDEV";
////conInfo.ServerName = "acer";
//conInfo.DatabaseName = "DedStaffApproval";
////conInfo.IntegratedSecurity = true;
////conInfo.UserID = "";
////conInfo.Password = "";

reportDoc.Load(Server.MapPath(Path.Combine("Reports", "prapatraAB.rpt")));
this.CrystalReportViewer1.ReportSource = reportDoc;

reportDoc.SetParameterValue("@yearid", yearid);
reportDoc.SetParameterValue("@collegeid", cmbcollege.SelectedValue);

reportDoc.DataDefinition.FormulaFields["Cyear1"].Text = "'" + c1 + "'";
reportDoc.DataDefinition.FormulaFields["Cyear2"].Text = "'" + c2 + "'";
reportDoc.DataDefinition.FormulaFields["Pyear1"].Text = "'" + p1 + "'";
reportDoc.DataDefinition.FormulaFields["Pyear2"].Text = "'" + p2 + "'";
reportDoc.DataDefinition.FormulaFields["region"].Text = "'" + rg + "'";
reportDoc.DataDefinition.FormulaFields["letnodate"].Text = "'" + letdate + "'";
reportDoc.DataDefinition.FormulaFields["varIO"].Text = "'" + VarIO + "'";
reportDoc.DataDefinition.FormulaFields["gdate"].Text = "'" + txtdate.Text + "'";
reportDoc.DataDefinition.FormulaFields["head"].Text = "'" + head + "'";
CREngine.Tables rptTables = reportDoc.Database.Tables;

foreach (CREngine.Table rptTbl in rptTables)
{
TableLogOnInfo repTblLogonInfo = rptTbl.LogOnInfo;
repTblLogonInfo.ConnectionInfo = conInfo;
rptTbl.ApplyLogOnInfo(repTblLogonInfo);
}

this.CrystalReportViewer1.ReportSource = reportDoc;
this.CrystalReportViewer1.DataBind();
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.Width = 100;



ExportOptions exportOpts = new ExportOptions();
PdfRtfWordFormatOptions pdfOpts = ExportOptions.CreatePdfRtfWordFormatOptions();
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.ExportFormatOptions = pdfOpts;
reportDoc.ExportToHttpResponse(exportOpts, Response, false, "Report");



//this.CrystalReportViewer1.ReportSource = reportDoc;
//this.CrystalReportViewer1.DataBind();
//reportDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, this.Response, true, "rptprapatraAB");

}
catch (Exception ex)
{

}
finally
{
reportDoc.Dispose();
reportDoc.Close();
CrystalReportViewer1.Dispose();
}
Posted

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