Page 1 of 1

Cannot set Variables at runtime though a c# application

Posted: Thu Jan 27, 2011 9:53 pm
by mathat1970
I am trying to allocate a value for Report Designer variable from a C#.net application.

The value is not however being displayed ... either I am referenceing the field incorrectly or the value cannot be allocated at runtime in this manner.

Can someone please confirm that this can be done or not ?

And if it can be done I would appreciate some pointers.

Please find below the snippets of from within my C# application

Code: Select all

Dictionary ReportVariableValue;
....
foreach(KeyValuePair pair in ReportVariableValue)
{
    report.Dictionary.Variables[pair.Key].Value = pair.Value;
}
Precondions:

* ReportVariableValue has valid data i.e. pair.Key is the variable name in the stumulsoft designer e.g. "VirtualPageNo" and pair.Value has a valid string e.g. "1"
* Report is compiled

Postconditions:

* I have checked through debug mode and determined that report.Dictionary.Variables[] has the correct values
* I then do an export to a PDF .... the report is displayed as a PDF but the Variables I have changed have not been set the runtime values.


Cannot set Variables at runtime though a c# application

Posted: Fri Jan 28, 2011 1:29 am
by Martin Hart Turner
Hi:

I have also had lots of fun with this topic :amazed:

In the preconditions you say the report is compiled, but how do you check this?

What I am trying to say is that there are two variables you should be checking:
- report.IsCompiled
- report.NeedsCompiling

If the report IsCompiled and NeedsCompiling is false you should be okay to set the variables and they should work as expected.

HTH,
Martin.

Cannot set Variables at runtime though a c# application

Posted: Fri Jan 28, 2011 5:23 am
by Alex K.
Hello,

If report not compiled then you can use the following code:

Code: Select all

report.Dictionary.Variables[pair.Key].Value = pair.Value;
else

Code: Select all

report[pair.Key] = pair.Value;
In some cases, you must create a report without compilation. For this purpose the NeedsCompilling property was added.

Thank you.

Cannot set Variables at runtime though a c# application

Posted: Sun Jan 30, 2011 7:36 pm
by mathat1970
Thankyou both for your help and knowledge of the system.

I got it work with the code sample supplied i.e.

Code: Select all

report[pair.Key] = pair.Value;
I also now have a better understanding.

thanks again.




Cannot set Variables at runtime though a c# application

Posted: Mon Jan 31, 2011 2:25 am
by Alex K.
Hello,

We are always glad to help you!
Let us know if you need any additional help.

Thank you.