Flexreport dynamically setting connection string for sub report in WinForms

Posted by: alhad on 26 July 2019, 7:40 am EST

    • Post Options:
    • Link

    Posted 26 July 2019, 7:40 am EST

    Hi,

    I am using Flexviewer to display a report with a sub-report in a winforms application. I am using xsd files as the datasource for the main and sub-reports. The problem is that while the main report displays correctly each time, the sub-report keeps showing earlier data even when the xsd file has been generated correctly when the user views the report with different parameters.

    This is my code:

    
    C1.Win.FlexViewer.C1FlexViewer c1FlexViewer1 = new C1.Win.FlexViewer.C1FlexViewer();
            C1.Win.FlexReport.C1FlexReport report = new C1.Win.FlexReport.C1FlexReport();
    c1FlexViewer1.UserAction += C1FlexViewer1_UserAction;
    string reportfile = Application.StartupPath + "\\Reports\\TMProfFees.flxr";
    // Sub-report
    report.Load(@reportfile, "TMPmtAddDeductReport");
    report.DataSource.ConnectionString = Application.StartupPath + "\\Reports\\TMPmtAddDeduct.xsd";
    // Main Report
    report.Load(@reportfile, "TMProfFeesReport");
    report.DataSource.ConnectionString = Application.StartupPath + "\\Reports\\TMPmtDetail.xsd";
    c1FlexViewer1.DocumentSource = report;
    c1FlexViewer1.DocumentSource.GenerateCompleted += DocumentSource_GenerateCompleted;
    c1FlexViewer1.StatusText = "Loading....";
    c1FlexViewer1.Show();
    c1FlexViewer1.Dock = DockStyle.Fill;
    c1FlexViewer1.Cursor = Cursors.WaitCursor;
    c1FlexViewer1.Enabled = false;
    
    

    Thanks in advance.

    Regards,

    Alhad

  • Posted 29 July 2019, 6:55 am EST

    Hello Alhad,

    >>The problem is that while the main report displays correctly each time, the sub-report keeps showing earlier data

    Do you point to the main report data when you say “earlier data”?

    Please refer the below mentioned code snippet from your code:

    // Sub-report
    report.Load(@reportfile, "TMPmtAddDeductReport");
    report.DataSource.ConnectionString = Application.StartupPath + "\\Reports\\TMPmtAddDeduct.xsd";
    // Main Report
    report.Load(@reportfile, "TMProfFeesReport");
    report.DataSource.ConnectionString = Application.StartupPath + "\\Reports\\TMPmtDetail.xsd";
    

    You are setting the “report” instance of FlexReport with the sub-report first, and then with the main report. Thus, the main report is what finally remains in that report instance due to which you might be seeing the main report’s data in it, instead of sub-report data.

    You may want to use two different instances for the two reports, say report1 for main report and report for sub-report, as follows:

    C1.Win.FlexReport.C1FlexReport report = new C1.Win.FlexReport.C1FlexReport();
    C1.Win.FlexReport.C1FlexReport report1 = new C1.Win.FlexReport.C1FlexReport();
    // Sub-report
    report.Load(@reportfile, "TMPmtAddDeductReport");
    report.DataSource.ConnectionString = Application.StartupPath + "\\Reports\\TMPmtAddDeduct.xsd";
    // Main Report
    report1.Load(@reportfile, "TMProfFeesReport");
    report1.DataSource.ConnectionString = Application.StartupPath + "\\Reports\\TMPmtDetail.xsd";
    

    If the issue persists, please share your stripped down application. This will help me assist you further.

    Regards,

    Esha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels