Load Code - Variables vs. Parameters

Stimulsoft Reports.NET discussion
Post Reply
ianwelsh
Posts: 19
Joined: Mon Sep 25, 2017 1:54 pm

Load Code - Variables vs. Parameters

Post by ianwelsh »

For reports that utilize variables and parameters (where a variable is tied to a parameter) does the aspx viewer page need to set the variable value, the parameter value, or both?

And when would that happen in the process of load/compile/render?

I've put together the following code based on examples and am not sure if it's correct, or whether I need the parameter loop given that the only variables we use are tied to parameters. Maybe better safe than sorry and do both? Or would that make the page load slower/less efficient?

Code: Select all

StiReport oReport = new StiReport();
oReport.Load(sReport);

foreach (StiSqlDatabase oConnection in oReport.Dictionary.Databases)
	oConnection.sConnectioning = sConnection;

oReport.Compile();

foreach (StiVariable oVariable in oReport.Dictionary.Variables)
	{
	string sValue = oParams[oVariable.Name];
	if (!String.IsNullOrEmpty(sValue))
	{
		try
		{
			object castValue = TypeDescriptor.GetConverter(oVariable.Type).ConvertFromInvariantString(sValue);
			oReport.CompiledReport.Variables[oVariable.Name] = castValue;
		}
		catch (Exception) { }
	}
}

/*  Do we need to do BOTH variables AND parameters loops? < ----------------------------------------------------------

foreach (StiDataSource oDatasource in oReport.DataSources)
	{
	foreach (StiDataParameter oParameter in oDatasource.Parameters)
	{
		string sValue = oParams[oParameter.Name];
		if (!String.IsNullOrEmpty(sValue)) 
		{
			try
			{
				object castValue = TypeDescriptor.GetConverter(oParameter.Type).ConvertFromInvariantString(sValue);
				oParameter.ParameterValue = castValue;
			}
			catch (Exception) { }
		}
	}
}
*/

oReport.Render(false);
StiWebViewer1.Report = oReport;
oReport.Dictionary.DataStore.Clear();
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Load Code - Variables vs. Parameters

Post by HighAley »

Hello.

We don't see your whole code.
Based on that we see we can say that it's enough to set the variable's values.
You should do it this way after compilation and before rendering.
The data are requested at the beginning of rendering.

Thank you.
ianwelsh
Posts: 19
Joined: Mon Sep 25, 2017 1:54 pm

Re: Load Code - Variables vs. Parameters

Post by ianwelsh »

Do I need the parameter value setting loop or no, given that my parameters are set to variable values?
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Load Code - Variables vs. Parameters

Post by HighAley »

Hello.

If your parameters take values from the variables, you don't need the second loop though the parameters.

Thank you.
Post Reply