two sub report in report

Stimulsoft Reports.WEB discussion
Post Reply
m.naqash
Posts: 5
Joined: Sun Aug 26, 2012 7:22 am

two sub report in report

Post 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
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: two sub report in report

Post by Alex K. »

Hello,

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

Thank you.
m.naqash
Posts: 5
Joined: Sun Aug 26, 2012 7:22 am

Re: two sub report in report

Post 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,
Attachments
two sub report samle.rar
(269.8 KiB) Downloaded 234 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: two sub report in report

Post 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.
m.naqash
Posts: 5
Joined: Sun Aug 26, 2012 7:22 am

Re: two sub report in report

Post 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
Attachments
testReport.mrt
(13.42 KiB) Downloaded 536 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: two sub report in report

Post 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.
Post Reply