Setting parameter in precompiled reports

Stimulsoft Reports.NET discussion
Post Reply
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Setting parameter in precompiled reports

Post by simgschw »

Hi,

I have a report which uses data from a database connection. The queries of the datasources need some parameters which are defined as report parameters. I programmactically generate thousands of reports each day. The difference of these reports are the parameter values.

Imagine, loading thousands of reports, setting the parameter values, compiling the reports, rendering the reports and saving them as pdf dokuments ... This workflow takes a lot of time and maybe this is a waste of time when using precompiled reports.

I tested report generation with precompiled reports with simple report templates. This worked, but when increasing the complexity of the report it didnt' work any more.


In my project I loading the report like this (from http://admin.stimulsoft.com/Documentati ... _asse3.htm):

Code: Select all

C#

 

string reportName = "MyReport.mrt";
string reportDllName = "MyReport.dll";
StiReport report = null;

// if report dll is not exists ...
if (!File.Exists(reportDllName))
{
   // load report definition
   report = new StiReport();
   report.Load(reportName);
   // compile report, save dll version of report
  report.Compile(reportDllName);
}
else // if report assembly is available …
{
    // … use it
   report = StiReport.GetReportFromAssembly(reportDllName);
}
To reproducing this bug/issue you can find a c# project in the attachments. This project is from your sample projects (SqlParameters). I did some changes in the code to reproduce my issue. You can find my changes in this method from Form1.cs:

Code: Select all

private void button1_Click(object sender, System.EventArgs e)
{
            string reportDllName = "Report.dll";
            stiReport1.Compile(reportDllName);
            //without next statement report generating works!
            stiReport1 = StiReport.GetReportFromAssembly(reportDllName);
            for (int i = 0; i < lbCountries.Items.Count; i++) {
                setParameter(lbCountries.Items[i].ToString());
                stiReport1.Render(false);
                Export(lbCountries.Items[i].ToString());
            }
}
As you can read in my comment, when I do not load the report from the assembly, generating the reports works, but takes in my case too long. Loading the report from the assembly is rather fast, but doesn't work.


I hope I stated my issue/problem clear enough. In any case take a look at the c# project in the attachment.


Thx in advance, greetings
Attachments
SqlParameters.zip
C# project to reproduce issue/problem/bug
(274.53 KiB) Downloaded 168 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Setting parameter in precompiled reports

Post by Alex K. »

Hello,

Please try to use the additional variable. Set this variable in parameter expression in datasource. And in code set the value for this variable.

Thank you.
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: Setting parameter in precompiled reports

Post by simgschw »

Hi,

as you suggested I added a new dictionary variable. The value of the variable is set to the parameter's value of the datasource.

Project compiled and had no errors. In debug mode, i stepped through the run and opened the designer view for each report and it worked. but saving the generated reports to pdf or open them in the viewer didn't work.

Can you tell me what is wrong in my project?

Thx. greetings
Attachments
SqlParameters_01.zip
adapted c# project: same as before besides that a dictionary variable was added
(275.34 KiB) Downloaded 182 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Setting parameter in precompiled reports

Post by HighAley »

Hello.

If you use compiled report, all data sources are compiled to classes. So you could change the variable value in the compiled report with next code:

Code: Select all

report.CompiledReport["countryID"] = country;
Let us know if you will have any problem in the implementation.

Thank you.
simgschw
Posts: 73
Joined: Mon Jan 07, 2013 1:34 pm

Re: Setting parameter in precompiled reports

Post by simgschw »

Tried this solution and it works. But using the precompiled report with

Code: Select all

stiReport1 = StiReport.GetReportFromAssembly(reportDllName);
and setting the SQL-parameter with

Code: Select all

stiReport1[varName] = country
it does not work anymore.

Can you tell me how to set a parameter in a report that is loaded from assembly? What I mean by this, is that not only the setting is important but also that the report ist saved in the files correctly!

Please have a look at the adapted attachment!


Thx, greetings
Attachments
SqlParameters_02.zip
adapted version
(978.92 KiB) Downloaded 175 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Setting parameter in precompiled reports

Post by Alex K. »

Hello,

In this case please try to use the following code:

Code: Select all

stiReport1.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiOleDbDatabase("NorthWind", "NorthWind", "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" + path + "\\Data\\Nwind.mdb", false));
instead

Code: Select all

//stiReport1.RegData("NorthWind", connection);
In this case you can set the parameter value withou the additioanl variable.

Code: Select all

stiReport1["@countryID"] = country;
Thank you.
Post Reply