ActiveReports 6 Online Help
Run Time Data Sources
Show AllShow All
Hide AllHide All

ActiveReports allows you to change the data source of a report at run time. This walkthrough illustrates how to find the location of the sample database file on the user's computer and connect the report to it at run time.

This walkthrough is split up into the following activities:

Tip: For basic steps like adding a report to a Visual Studio project and viewing a report, please see the Basic Data Bound Reports walkthrough.

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).

When you have finished this walkthrough, you will have a report that looks similar to the following.

To connect the report to a design time data source

Tip: Even if you will change the data source at run time, setting a design time data source allows you to drag fields onto the report from the Report Explorer.
  1. Add an ActiveReport 6 (code-based) File to a Visual Studio project, and rename the file rptModifyDS.
  2. Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  3. On the OLE DB tab, click the Build button.
  4. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
  5. Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to continue.
  7. In the Query field, paste the following SQL query.
    SQL Query
    Copy Code
    SELECT * FROM Products
  8. Click OK to return to the report design surface.

To add controls to the report

  1. Click the detail section to select it, and in the Properties Window, set the CanShrink property to True.
  2. In the Report Explorer, expand the Fields node, then the Bound node.
  3. Drag the following fields onto the detail section of the report and set the properties of each textbox as indicated.

Detail section fields

To find the database path

  1. Right-click in any section of the design window of rptModifyDS, and select View Code to display the code view for the report.
  2. Add code to the report to get the sample database path from the registry.

To write the code in Visual Basic

To write the code in C#

To change the data source at run time

  1. Double-click in the gray area below rptModifyDS to create an event-handling method for the ReportStart event.
  2. Add code to the handler to change the data source at run time.

To write the code in Visual Basic.NET

To write the code in C#

To close the data connection

To write the code in Visual Basic

To write the code in C#

See Also

Concepts

How To