ActiveReports for .NET 3 Online Help Request technical support
Parameters
See Also
User Guide > Concepts > Parameters

Glossary Item Box

Parameters and Simple Reports

In ActiveReports for .NET 3.0, you can allow users to filter the amount of information exposed in a report through the use of parameters. Adding parameters to the report results in a Parameters dialog that the user can manipulate against the database to return pertinent data.

For example, the SQL statement "SELECT * FROM products INNER JOIN categories ON products.categoryid = categories.categoryid WHERE products.supplierID =<%SupplierID|Enter supplierID|1000%> and OrderDate=#<%Date|Order date:|1/1/2001|D%># and Discount=<%bool| Is this checked ?|true|B%>;" contains unique syntax that ActiveReports for .NET uses to generate the following dialog. 

 

Breaking down the SQL statement, the syntactical elements <%SupplierID|Enter supplierID|1000%>, <%Date|Order date:|1/1/2001|D%>,  and <%bool| Is this checked ?|true|B%> comprise the report parameters. The user can accept these or input other values to further define report data. Each of these parameters follow the syntactical pattern <%FieldName | PromptString | DefaultValue | Type%> where:

 

You can use stored procedures in the same way as parameters in ActiveReports. The SQL statement has the stored procedure call and placeholders for the parameters: "CustOrderHist <%ID|Enter Customer ID:|AFLKI%>". ActiveReports replaces the parameter text "<% %>" with whatever the user types into the dialog to create a call like this: CustOrderHist 'AFLKI'.

To add parameters in SQL statements as in the above example, you will need to add them to the query via the Datasource dialog that is accessed by clicking the datasource icon in the ActiveReports designer.

Adding Parameters Via the Report Explorer

In addition to adding parameters in SQL statements, ActiveReports for .NET 3.0 provides for the addition of parameters via the Report Explorer. To do so, right-click the Parameters node in the Report Explorer and click "Add" from the shortcut menu. This will add a child to the Parameters node.

 

Once a parameter is added to the Report Explorer, you can set its properties from the Properties grid. 

Adding Parameters at Run time

Custom parameters can be added, edited, and deleted at run time. The following demonstrates how to add a parameter to the Report_Start event and assign its value to an ActiveReports' textbox control.

'Visual Basic
Private Sub rptParam_ReportStart(ByVal sender As System.Object, ByVal e As System.EventArgs)_ 
   Handles MyBase.ReportStart
	
   Dim myParam1 As New Parameter()
   myParam1.Key = "myParam1"
   myParam1.Type = Parameter.DataType.String
   myParam1.PromptUser = True 'set to False if you do not want input from user
   myParam1.Prompt = "Enter last name:"
   myParam1.DefaultValue = "This is myParam1 default value"
   Me.Parameters.Add(myParam1)
   
   'Set textbox text equal to the value of the parameter
   Me.txtParam1.Text = Me.Parameters("myParam").Value
End Sub

//C#
private void NewActiveReport1_ReportStart(object sender, System.EventArgs e)
   {
    Parameter myParam1 = new Parameter();
    myParam1.Key = "myParam1";
    myParam1.Type = Parameter.DataType.String;
    myParam1.PromptUser = true; //set to false if you do not want input from user
    myParam1.Prompt = "Enter last name:";
    this.Parameters.Add(myParam1);
    
    //Set textbox text equal to the value of the parameter
    this.txtParam1.Text = this.Parameters["myParam"].Value;			
   }	

Parameters and Subreports

You can use parameters with subreports to connect the subreport to the parent report. If you set a parameter for the field that links the parent report to the child subreport, the parent report passes the information to the child through the parameters. Keep the following in mind when working with subreports and parameters:

Both report queries must contain the same field (so the main report must have a categoryID field and the subreport also must have a categoryID field.

See Also

©2009. All Rights Reserved.