Page 1 of 1

Load Code - Variables vs. Parameters

Posted: Tue Feb 06, 2018 2:23 pm
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();

Re: Load Code - Variables vs. Parameters

Posted: Tue Feb 06, 2018 4:09 pm
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.

Re: Load Code - Variables vs. Parameters

Posted: Tue Feb 06, 2018 7:15 pm
by ianwelsh
Do I need the parameter value setting loop or no, given that my parameters are set to variable values?

Re: Load Code - Variables vs. Parameters

Posted: Tue Feb 06, 2018 10:15 pm
by HighAley
Hello.

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

Thank you.