Monday, January 25, 2010

Active Reports - Parameter Passing

Well, it has been awhile since I've posted. I've just been cruising along with the coding, just a matter of getting it done rather than running into walls. I thought I would post a simple little post on passing parameters or data to a report.

I'm sure there is some sort of an official way of passing data to Active Reports, but I usually take a simple route when it comes to coding. Last week, I needed to pass data to a report, so I googled it. And sure enough, it was easy. I was in the mode of "this is reporting, it is limited!". Of course, Active Reports are also Classes so that was the answer to my problem!

I created private attributes that have Properties defined - getter and setter, although I only needed the setter.

so pretty much it is just like any class. here's the code snippet:

public partial class SummaryReport : DataDynamics.ActiveReports.ActiveReport
{

private bool _showPicture = true;

public bool ShowPicture
{
get { return _showPicture; }
set { _showPicture = value; }
}
.....

so to pass data outside this report, I would call:

SummaryReport rpt = new SummaryReport();
rpt.ShowPicture = false;


That's it. Pretty easy, but possibly overlooked.

}

5 comments:

  1. Cool. The great thing about ActiveReports is that you can use it just like any other class.
    ActiveReports also has a special provision for passing parameters into a report that can be used in the SQL statements. It also can be used to prompt users for input automatically. You can see more about it at the following links:
    - http://www.datadynamics.com/Help/ActiveReports6/ActiveReports6_start.html?arHOWAddParameters.html
    - http://www.datadynamics.com/forums/539/ShowPost.aspx

    ReplyDelete
  2. thanks for the tip scott. i see you are working at data dynamics? that's cool. i've been very happy with AR6. Learning new stuff everyday!

    ReplyDelete
  3. Hi Programming girl.
    Whenever I try to figure something out about ActiveReports, your blog always ends up on the first page of search results!

    My question for you is, I have a report and a subreport. I am passing a few parameter values from the report to the subreport. I am using 2 of the values in the SQL statement, and can use those values on the report...this is successful, in other words. 2 other values need to be accessible even if the SQL statement doesn't return any data. How can I read the parameters just from the scripting side, and not rely on the sql statement returning anything?

    I would really appreciate your help.

    THANKS!

    ReplyDelete
  4. Although, I'm not exactly sure how your report is working, my first guess is that if you set up the Properties as this example shows, you can then call those values in the methods, maybe like this:

    if(_showPicture)
    xxxxx....

    or like this...

    txt.Value = _showPicture

    BUT you say 'scripting' so I'm not sure if those values are accessible there. This example would be the 'code-behind'.

    Scott, often reads this blog and he may know a little more than I do, since he's an insider. Scott any ideas????

    ReplyDelete
  5. @cptacek: You should be able to access them in the code/script of the report using something like the following:

    Debug.WriteLine("myParamName=" + this.Parameters["myParamName"].Value);


    See the following documentation URL for more details: http://bit.ly/b47dAF

    ReplyDelete