I need to pass parameters (variables) in to my document template when running a report. How do I do this? I am using the .NET version of Windward.
-
Which part of your code didn't work? What error did you get? – L.B Aug 26 '12 at 21:25
-
@L.B I am putting up the common questions we get at Windward so users can find the solution immediately here. This is the most common programming question we get. (I guess it makes sense that the most common questions tend to be simple - complex questions tend to be user specific.) – David Thielen Aug 26 '12 at 21:27
-
But `How do I do this` is not a good fit for SO. SO expects `How can I fix this` type questions, encouraging doing the research by yourself – L.B Aug 26 '12 at 21:33
-
@L.B I think it fits. It lists how to accomplish this programming task. Similar to someone asking how they can insure 3 lines of code are executed as an atomic set per thread. The answer is "use the synchronized statement" (Java). – David Thielen Aug 26 '12 at 21:37
1 Answers
You pass the parameters in by attaching them to each datasource. You can set a different set of parameters and values for each datasource.
You do this by creating a WindwardInterfaces.net.windward.api.csharp.KeyPairDictionary that contains the parameters. The key is a String with the variable name. The value can be a String, Number, or DateTime. The value type should match database column types if the variable will be used as a parameter in a select.
These are set in the datasource by assigning to the IReportDataSource.Map property. AdoDataSourceImpl and XmlDataSourceImpl both implement IReportDataSource.
IReportDataSource datasource = new XmlDataSourceImpl("data.xml");
KeyPairDictionary map = new KeyPairDictionary();
map.Add("now", DateTime.Now);
datasource.Map = map;
Note that variables are carried across datasources if multiple datasources are applied to a template. If a variable is set in the first datasource, and is not set in the second, it will retain its value from the first. If it is set in the second, that will override the saved value.

- 28,723
- 34
- 119
- 193