Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send parameters to Subreport in Crystal Reports

Using VS 2008.

I have two stored procedures, one used to get data for the main report and other for Sub report and both the SP's use the same parameter QuoteID.

I have send parameter to main report using ReportDocument. But I am not aware how to send parameters to SubReport.

I tried many diff ways using the reportdocument's setparameter method which also takes subreport name as argument.But it didn't.

Below is the code I have used

    string Type = gvQuotationDetails.Rows[QuoteIndex].Cells["Type"].EditedFormattedValue.ToString();

    FilePath = ConfigurationManager.AppSettings["EMP_IMG_PATH"].ToString() + "\\" + ValQuoteID.ToString() + ".pdf";

    DeleteExistingFile(FilePath);

    try
    {
        AccountsPayableMaster objAPM = new AccountsPayableMaster();
        QuotationReport obj = new QuotationReport();
        objReportDocument.Load(Application.StartupPath + @"\rptQuotationReport.rpt");
        obj.crysQuotationReport.LogOnInfo = objAPM.ConnectionDetails("SD_SalesOrderReport;1");
        obj.crysQuotationReport.LogOnInfo = objAPM.ConnectionDetails("SD_GetBatchReportDetails;1");
        obj.crysQuotationReport.ReportSource = objReportDocument;
        objReportDocument.SetParameterValue("@QuoteID", ValQuoteID);
        objReportDocument.SetParameterValue("Type", Type);
        //objReportDocument.Subreports[Application.StartupPath + @"\BatchSubReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);
        //objReportDocument.Subreports["BatchReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);           

        string[] Print = objAPM.GetPrintDetails();

        SetPrintParameters(objReportDocument, Print);

        obj.Show();

        objReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, FilePath);
    }

    catch (Exception ex)
    {
        MessageBox.Show(ex.Message); 
    } 

Sending parameter to Subreport

//objReportDocument.Subreports[Application.StartupPath + @"\BatchSubReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);

//objReportDocument.Subreports["BatchReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);              

////objReportDocument.SetParameterValue("@QuoteID", ValQuoteID,"BatchReport.rpt);

nothing worked.I have already wasted two days on this. [SD_SalesOrderReport;1] main SP and [SD_GetBatchReportDetails;1] subreport SP.

It would be great if someone can provide a solution for this.If there are some changes to be made in designed please share images.Thank you.

like image 980
Prathap Avatar asked Feb 23 '13 05:02

Prathap


People also ask

How do you link parameters in Crystal Reports?

In the top left box, select the field from the main report that will be linked to the subreport. Click on the right arrow button to move the field to the top right box. In the bottom right drop down list, select the field from the subreport that will be linked to the main report. Click OK.

How do I link subreport to main report in Crystal Report?

Select Subreport tab from Format Editor , you can find there a check box On-demand Subreport . You have to select that check box , then the subreport become as a link in your main Crystal Reports. If you want to change the title , you can change it in subreport name textbox. Finally click OK button.

How does a subreport work in Crystal Reports?

Subreports allow you to combine unrelated reports into a single report. It is a report within a report. You can combine data that cannot be linked and present different views of the same data in a single report.

Can you have a subreport in a subreport in Crystal Reports?

So basically you cannot have a subreport within a subreport. If you try to insert a subreport that has a subreport, the ineermost subreport is not rendered when the report is run. This is by design. You also cannot link 2 subreports with one another.


1 Answers

Finally after lot of trails, I have solved it.May be this will be helpful to others.I have used the same parameter Name for Main and SubReport, used below code to set its parameter

objReportDocument.SetParameterValue("@QuoteID", ValQuoteID,objReportDocument.Subreports[0].Name.ToString());
like image 195
Prathap Avatar answered Nov 15 '22 06:11

Prathap