Crystal Report Sub Report Using C#
I have built an application using C#.net and Crystal Reports which are exported to PDF. The reports I have been using have been running very well. I generate the report from a dataset at runtime (see code below)
I have tried to modify some of my reports to include a sub-report which I have built an run separately as a report first.
I have included the sub report in the details section of the main report and specified the link field. I get errors when I try to run it.
I do not know how to write the C# code to get the sub report to run from the main report.
I have been unable to find any examples anywhere on the net or in books. It must be quite simple because these sub-reports are very common.
The code I use to generate the main report is below. I mostly understand this. Could anybody be so kind as to show me how to modify my code below to include the sub-report in the main report.
/// Summary description for InvoiceItemReport.
public class InvoiceItemReport : System.Web.UI.Page
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected ElecCon.Invoice.InvoiceItem1.DataSet77 dataSet771;
protected System.Web.UI.WebControls.Button Button1;
InvoiceItemDetailReport report = new InvoiceItemDetailReport();
private void Page_Load(object sender, System.EventArgs e)
sSQLSelect = Session["ReportSelectionString"].ToString();
private void SetUpReport()
DataSet dataSet771 = new DataSet();
string sSQL = "SELECT invoice_Item_UID, job_Pack_UID, proj_Account_No,cpm_No, contract_UID, contract_Abbr, contract_Descr, invoice_UID, quote, extra,complete, "+
"invoice_Comment, invoice_Date, invoice_Work_OH, invoice_Month, invoice_Year, progress_UID, progress, project_Name, project_Description, feeder, "+
"equipment, old_Pole_No, item_Completed_Date, assy_No, assy_Descr, assy_Descr_Short, cost_Code, uom, quantity, work_Kind_Abbr, "+
"work_Kind_Descr, company, company_Abbr, contractor, class_Abbr, class_Description, customer_UID, customer_Abbr, customer_Name, "+
"notification_Date, Price, age,extra_Type, comment, resource_Cost "+
" FROM dbo.vwInvoiceItems "+ sSQLSelect + "";
SqlConnection conn = new SqlConnection(ConnectDB.ConnectionString);
SqlCommand sqlCommand = new SqlCommand(sSQL, conn);
sqlCommand.CommandTimeout = 3600;
SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
string x = Request.Url.AbsolutePath.ToString();
Session["ErrorMessage"] = ex.ToString();
Session["OriginatingUrl"] = x;
#region Web Form Designer generated code
private void ExportTheReport()
ExportOptions exportOpts = new ExportOptions();
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
FName = "C:\\Temp\\JobPackReport.pdf";
diskOpts.DiskFileName = FName;
exportOpts = report.ExportOptions;
exportOpts.DestinationOptions = diskOpts;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
// write the pdf file to the Client browser
Response.ContentType = "application/pdf";
// delete the exported file from the disk