DiningPhilanderer
DiningPhilanderer

Reputation: 2767

Populate Custom Code variables from Database in SSRS 2008 R2

I am trying to populate variables in the Report Custom Code area (or even better a DLL in C#) from a DataSet so I can say "Code.SomeSetting". What is the best way to do this? If you pass a SSRS DataSet as a parameter to a method only the CommandText is available.

Is this even possible?

My other alternative would be to pass in the connection string and use C# to query the database and populate these variables as soon as possible.

Also Where can I read about the exact rendering order of an SSRS report? Thanks

Upvotes: 0

Views: 3953

Answers (2)

user4390047
user4390047

Reputation: 1

The only way I found to pass a datasets information into either a variable, parameter or custom code is through sub reports. Basically you are running the report first, not displaying any data (preprocessing) and sending preprocessed information into your sub–report only through the sub-report’s parameters.

  • This will allow you to:
  • send dataset data to variables, custom code, and parameters.
  • Send aggregate data to variables, custom code, and parameters.

Here's how:

  1. Create 2 copies of your report.
    • For example: main_Report.rdl and sub_Report.rdl
    • main_Report.rdl should have matching Data Sources and Datasets as sub_Report.rdl.
    • Sub_Report.rdl is your original report with the parameters, custom code and variables the way you want it but that did not work
  2. Optional: Design your header and footer for main_Report.rdl
  3. Inside Main report insert a “sub-report” and change its size to fill all the space of your main_Report.rdl
  4. Connect the sub report
    • Right click on sub-report -> choose “Subreport Properties”
    • In General section
    • -> “Name”: name your sub-report
    • -> “Use this report as a sub-report”: choose your sub-report name for example
  5. Pass your data
    • In the Parameters section
    • Click add
    • -> In the name column: choose your parameter
    • -> In the value column: use expressions to pass your data into your sub_report

Enjoy

Upvotes: 0

Etch
Etch

Reputation: 3054

Here are 2 links I have favorited to use as reference for the custom code.

MSDN. Alot of data here, but an excellent resource. BlogPost Robert Bruckner is the lead developer on SQL Reporting Services. Another excellent resource. This post is more about aggregating aggregates in the Custom Code, but it gives you a good example to look at.

Upvotes: 2

Related Questions