There are several ways to add parameters in a section report. The following sections provide a step by step overview of adding parameters in a report.
To add parameters using the Report Explorer
- In the Report Explorer, right-click the Parameters node and select Add. This adds a parameter (Parameter1) as a child to the Parameters node.
- Select the added parameter to open the Properties Window and set values in the following properties:
- Name: This is the unique name of the parameter which appears as Parameter1 by default. It corresponds to the Key property in parameters entered via code.
- Default Value: Sets/returns the value displayed when the user is prompted to enter a value at runtime.
- Prompt: Sets/returns a string displayed when a user is prompted for the value at runtime.
- PromptUser: Boolean value that indicates whether to prompt the user for a value or not. This is set True to use parameters at runtime.
- Type: This value which defaults to String defines the type of data the parameter represents. You can also set data type to Date or Boolean.
- Pass the parameter to a field on the report, or access it programmatically as described in the run time procedure below.
To add parameters directly using a SQL query
When you add SQL parameters to a report, ActiveReports Developer displays an Enter Report Parameters dialog where the user can enter the values to fetch from the database.
- In the detail section band, click the DataSource icon to view the Report Data Source dialog.
- Connect the report to a data source, for example, OleDb data source. See Bind Reports to a Data Source for further details.
- In the Query field, enter a SQL query like the one below, which contains the parameter syntax to prompt for parameter values at runtime.
SELECT * FROM Products
INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID= [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID WHERE Products.SupplierID = <%SupplierID|Enter Supplier ID|7%>
AND OrderDate >= #<%OrderDate|Order date from|11/1/1994|D%>#
AND Discontinued = <%Discontinued|Is this checked?|true|B%> - Click OK to save the data source and return to the report design surface.
The SQL query above causes ActiveReports to display the following dialog to the user. The user can accept these or input other values to select report data.
To add parameters at run time
You can add, edit, and delete parameters at run time. The following code demonstrates how to add a parameter and display its value in a Textbox control.
- Double-click in the gray area below the report to create an event-handling method for the ReportStart event.
- Add code to the handler to set parameters at run time.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste at beginning of code view. Copy Code Imports GrapeCity.ActiveReports.SectionReportModel
Visual Basic.NET code. Paste INSIDE the ReportStart event. Copy Code Dim myParam1 As New Parameter()
myParam1.Key = "myParam1"
myParam1.Type = Parameter.DataType.String
'Set to False if you do not want input from user.
myParam1.PromptUser = True
myParam1.Prompt = "Enter Data:"
myParam1.DefaultValue = "Default Value"
Me.Parameters.Add(myParam1)C# code. Paste at beginning of code view. Copy Code using GrapeCity.ActiveReports.SectionReportModel;
C# code. Paste INSIDE the ReportStart event. Copy Code Parameter myParam1 = new Parameter();
myParam1.Key = "myParam1";
myParam1.Type = Parameter.DataType.String;
//Set to False if you do not want input from user.
myParam1.PromptUser = true;
myParam1.Prompt = "Enter Data:";
myParam1.DefaultValue = "Default Value";
this.Parameters.Add(myParam1); - In the design view, click the gray area below the report to select it and open the Properties Window.
- Click the events icon in the Properties Window to display available events for the report.
- Double-click FetchData. This creates an event-handling method for the report's FetchData event.
- Add code to the handler to pass the parameter at run time.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the FetchData event. Copy Code 'Set textbox text equal to the value of the parameter.
Me.txtParam1.Text = Me.Parameters("myParam1").ValueC# code. Paste INSIDE the FetchData event. Copy Code //Set textbox text equal to the value of the parameter.
this.txtParam1.Text = this.Parameters["myParam1"].Value;
Viewing a Parameterized Report
The parameter prompt dialog for a parameterized report depending on how you view the report.
- In the Visual Studio project, add a Viewer control to the Form.
- Double-click the Form title bar to create a Form_Load event.
- Add the following code to the handler to view the report in the Viewer.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form_Load event. Copy Code Dim rpt As New SectionReport1
Viewer1.Document = rpt.Document
rpt.Run()C# code. Paste INSIDE the Form_Load event. Copy Code SectionReport1 rpt = new SectionReport1();
viewer1.Document = rpt.Document;
rpt.Run();
To get a Parameter Panel in the Viewer sidebar
- In the Visual Studio project, add a Viewer control to the Form.
- Double-click the Form title bar to create a Form_Load event.
- Add the following code to the handler to view the report in the Viewer.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form_Load event. Copy Code Dim rpt As New SectionReport1
Me.Viewer1.LoadDocument(rpt)C# code. Paste INSIDE the Form_Load event. Copy Code SectionReport1 rpt = new SectionReport1();
viewer1.LoadDocument(rpt);
Concepts
Parameters