Setting SQL-parameters before rendering

Stimulsoft Reports.NET discussion
Post Reply
rbarton
Posts: 5
Joined: Thu Dec 13, 2012 7:30 pm

Setting SQL-parameters before rendering

Post by rbarton »

Hello,

I'm trying to apply values to pre-defined SQL parameters in a report template before rendering the report using Stimulsoft.Net. My SQL query uses named parameters with the @-syntax, and the individual parameters are registered with the data source.

I've found the following entry in section 2.5 of the Reports.Net FAQ:

Code: Select all

report.Compile();
report["@customerid"] = 1;
But I was unable to get any SQL-parameters set via this method to apply -- no changes were seen in the rendered report.

I was finally able to get this to work by creating a new report variable for each SQL-parameter, entering that report variable name into the definition of the SQL-parameter via the report designer, and then using code similar to the above (referring to the variable name, without the @-symbol used only for parameters) to set the report variable programmatically, which then sets the associated SQL-parameter. This is what I'm using for now.

Is there a way to do this directly, without creating a report variable for each SQL-parameter? Thanks in advance.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Setting SQL-parameters before rendering

Post by Alex K. »

Hello,

We couldn't reproduce this bug.
Can you please send us your report with test data which reproduces the issue for analysis.

Thank you.
rbarton
Posts: 5
Joined: Thu Dec 13, 2012 7:30 pm

Re: Setting SQL-parameters before rendering

Post by rbarton »

Working to produce a small test report with SQL script etc. to reproduce.

In the meantime, is there a way to programmatically inspect which parameters are defined in the underlying data source of a loaded report template?

For example, with report variables, we can do the following:

Code: Select all

foreach (Stimulsoft.Report.Dictionary.StiVariable rptVar in report.Dictionary.Variables)
{
}
Is there a similar syntax to retrieve a set of SQL parameters defined as part of the report template?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Setting SQL-parameters before rendering

Post by Alex K. »

Hello,

As a way, you can use the following code:

Code: Select all

foreach (StiDataSource ds in report.DataSources)
{
    if (ds.Parameters.Count != 0)
    {
        foreach (StiDataParameter param in ds.Parameters)
        {
            ...
        }
    }
}
Thank you.
Post Reply