Passing a Hashtable to variable not working

Stimulsoft Reports.NET discussion
Post Reply
fuhrj
Posts: 120
Joined: Wed Jun 11, 2008 12:51 pm
Location: Lancaster, Ohio

Passing a Hashtable to variable not working

Post by fuhrj »

I need to send a Hashtable to my report, so I created a new variable with a type of 'object'

In my app, I am passing the hashtable using this code:

Code: Select all

if (report.Dictionary.Variables["statusDictionary"] != null) {
                    report.Dictionary.Variables["statusDictionary"].Type = typeof(Hashtable);
                    Hashtable testHash = new Hashtable();
                    testHash.Add("0","Jen");
                    testHash.Add("1", "Roy");

                    report.Dictionary.Variables["statusDictionary"].ValueObject = testHash;
                }

On the report side, I'm casting the variable like this:

Code: Select all

Hashtable statuses = (Hashtable)this.statusDictionary;
this.Label5.Text = statuses.Count.ToString();
I don't get any errors, but count is always 0. When I step through the code on the app side, report.Dictionary.Variables["statusDictionary"].ValueObject shows null even after I set it with the 'testHash' object.

Any ideas? I'm using build 2009.2.411
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Passing a Hashtable to variable not working

Post by Jan »

Hello,

Please create variable. Type of variable - object. Before assigning report variable call report compilation:

report.Compile();
report["myvariable"] = hashTable;

In report you need use following code:

this.Label5.Text = ((Hashtable)myvariable).Count.ToString();

Thank you.
fuhrj
Posts: 120
Joined: Wed Jun 11, 2008 12:51 pm
Location: Lancaster, Ohio

Passing a Hashtable to variable not working

Post by fuhrj »

Thanks for the response, Jan.

When trying to use:

Code: Select all

report.Compile();
report.Dictionary.Variables["statusDictionary"] = testHash;

The compiler throws this error:
Cannot implicitly convert type 'System.Collections.Hashtable' to 'Stimulsoft.Report.Dictionary.StiVariable'
My code will compile if change it back to ["statusDictionary"].ValueObject = testHash;

However, when the report launches, I now get this Exception from the report:
System.InvalidCastException: Unable to cast object of type 'System.Object' to type 'System.Collections.Hashtable'

Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Passing a Hashtable to variable not working

Post by Jan »

Hello,

Please check my code.

Thank you.
fuhrj
Posts: 120
Joined: Wed Jun 11, 2008 12:51 pm
Location: Lancaster, Ohio

Passing a Hashtable to variable not working

Post by fuhrj »

Jan wrote:Hello,

Please check my code.

Thank you.
Oh, I see that you left out the Dictionary.Variables part. I'll give it another go.

Thanks!
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Passing a Hashtable to variable not working

Post by Ivan »

Hello,

Let us know if you need any additional help.

Thank you.
Post Reply