Code based variables won't show their value while running..

Stimulsoft Reports.NET discussion
Post Reply
theregister
Posts: 53
Joined: Wed Nov 27, 2013 5:24 pm

Code based variables won't show their value while running..

Post by theregister »

I´m losing my mind here, I've tried every example I've found online and still can't get it to work, this is the way im creating the variables on the code that generates the report:

Code: Select all

report.Dictionary.Variables.Add(New Stimulsoft.Report.Dictionary.StiVariable("test",""))
report("test") = "ANYTHING"
While it does show me the created variables on the gui, they contain absolutely nothing, any ideas on what I'm doing wrong? Thanks!
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Code based variables won't show their value while runnin

Post by Alex K. »

Hello,

Please try to use the following code:

Code: Select all

report.Dictionary.Variables("test").Value = "ANYTHING"
Thank you.
theregister
Posts: 53
Joined: Wed Nov 27, 2013 5:24 pm

Re: Code based variables won't show their value while runnin

Post by theregister »

And it works! Who would've thought lol. Thanks though, I have another question regarding this same thing, now that we managed to set an actual value for this variable, can this value be something else? I'm thinking about SQL code, so I can use a variable instead of a query while running the program, is this possible?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Code based variables won't show their value while runnin

Post by Alex K. »

Hello,

You can use the variable in SQL query:
for example: select * from Table where Column = {Variable}
Aslo you can set the sql command from code:

Code: Select all

((StiSqlSource)report.Dictionary.DataSources["DataSourceName"]).SqlCommand = newSqlCommand;
Thank you.
theregister
Posts: 53
Joined: Wed Nov 27, 2013 5:24 pm

Re: Code based variables won't show their value while runnin

Post by theregister »

Let's see I tried with a simple query and it worked, but I have 2 other doubts..

First, can I use variables inside of variables? I'll explain.. let's say I have this in a databand:

Code: Select all

SELECT * FROM {query}
and {query} contains this:

Code: Select all

myTable WHERE Id={value}
and {value} contains 5 for example.

When I try to set the whole query in the databand, I cannot retrieve the columns and it gives me the next error:

Code: Select all

Incorrect syntax near '}'.
I can put the value of {value} by myself, and it will retrieve the columns, but when I preview the report it will give me the same Incorrect syntax error.. so is there another way to do this?

And the second doubt, when I use variables that contain SQL code like we're doing here, is there any way to execute them outside of a databand? Say I want to run a specific query but I want the result of the query, a single value, to be shown on a single text label at the top of the report, but I don't want to specify a whole databand just for that one value, can this be done as well?

Thanks a lot for your support. :D
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Code based variables won't show their value while runnin

Post by Alex K. »

Hello,

Can you please send us your report which reproduce the issue for analysis.

Thank you.
Post Reply