Page 1 of 1

two sub report in report

Posted: Mon Oct 08, 2012 8:00 am
by m.naqash
Hello,
I trying to use two sub reports in my report, one in header and the other in footer, both header and footer in two external reports, but when i try to run the report it generated the following exception in this line report.Render(), the error message is ( An unhandled exception of type 'System.StackOverflowException' occurred in Stimulsoft.Base.dll )

the following is my code :

Code: Select all

StiReport report = new StiReport();
.
.
report.GetSubReport += new StiGetSubReportEventHandler(rep_GetSubReport);
report.GetSubReport += new StiGetSubReportEventHandler(rep_GetFooterReport);

report.Compile();

report.Render();
StiWebViewerFx1.Report = report;

    void rep_GetSubReport(object sender, StiGetSubReportEventArgs e)
    {
        StiReport rep = new StiReport();

        dt = (DataTable)hc.FetchData("Select * From Report where RepNameEn = 'Header' ");

        string a = ""; //save the report string

        if (hc.IsValidDT(dt))
        {
            DataRow[] rows = dt.Select("RepNameEn = 'Header'");
            DataRow dr = rows[0];

            a = dr["RepStringEdited"].ToString();
        }

        rep.LoadFromString(a);
        e.Report = rep;
    }

    void rep_GetFooterReport(object sender, StiGetSubReportEventArgs e)
    {
        StiReport rep = new StiReport();

        dt = (DataTable)hc.FetchData("Select * From Report where RepNameEn = 'Footer' ");

        string a = ""; //save the report string

        if (hc.IsValidDT(dt))
        {
            DataRow[] rows = dt.Select("RepNameEn = 'Footer'");
            DataRow dr = rows[0];

            a = dr["RepStringEdited"].ToString();
        }

        rep.LoadFromString(a);
        e.Report = rep;
    }

i am using stimulsoft.report.web 2012.2

thank you

Re: two sub report in report

Posted: Mon Oct 08, 2012 10:15 am
by Alex K.
Hello,

Can you please send us a sample project with test data which reproduces the issue for analysis.

Thank you.

Re: two sub report in report

Posted: Sun Dec 09, 2012 12:09 pm
by m.naqash
Hello,
regarding sample project that you requested, in the attachment you will find sample project with sample DataBase.

after the change connection string just press "Show Report" Button to display report.

thank you,

Re: two sub report in report

Posted: Tue Dec 11, 2012 6:30 am
by HighAley
Hello.

The value of the variable is been inserted in the report as is without any quote marks.
So you should change your query to the :

Code: Select all

select * from Employee where CONVERT(varchar(10),EmpID) = '{EmpID}'
Thank you.

Re: two sub report in report

Posted: Tue Dec 11, 2012 8:23 am
by m.naqash
Hello

I tried to add single quote to the query but when I tried to upload it from my sample project that I sent to you it generated the following error:
Incorrect syntax near '{'.
In this line of code:
int returnValue = smdinst.ExecuteNonQuery();

however I changed my query into : select * from Employee where EmpID = @EmpID, and the report working properly, you can see that in the new sample report in the attachment.

But the problem still exist, which is I can’t run my header in the subreport in the header band, and my footer in the subreport in the footer band. Until now and regarding the code I wrote in the sample project, the header still running in the subreport in the header band and in the subreport in the footer band, so how I can run my header in the subreport band, and my footer in the subreport in the footer band in my sample report in the same time ?

Thank you

Re: two sub report in report

Posted: Wed Dec 12, 2012 7:54 am
by HighAley
Hello.

You shouldn't use two methods for subreports.
Here is a sample code how to add 2 subreports:

Code: Select all

                        .....
            StiReport rep = new StiReport();
            rep.LoadFromUrl(@"D:\MainReport.mrt");
            rep.GetSubReport += new StiGetSubReportEventHandler(rep_GetSubReport);
            rep.Render();
            rep.Show();
                        .....
                        

        void rep_GetSubReport(object sender, StiGetSubReportEventArgs e)
        {
            StiReport rep = new StiReport();
            rep.LoadFromUrl(@"D:\SubReport.mrt");
            e.Report = rep;
        }

 void rep_GetSubReport(object sender, StiGetSubReportEventArgs e)
       {
           StiReport rep = new StiReport();
           if (e.SubReportName == "SubReport1")   rep.LoadFromUrl(@"D:\SubReport1.mrt");
           if (e.SubReportName == "SubReport2")   rep.LoadFromUrl(@"D:\SubReport2.mrt");
           e.Report = rep;
       }
Thank you.