How to use internal data source in a FastReport .NET report

2016-02-24

If you create a report along with the client application, it is logical to create a single source of data in a program and use it in many reports.

This article will focus on the connection of the report FastReport .NET applications to the data source.

It is best to demonstrate the process by an example. Create application Windows Forms. Add the data source to the program. In my case - the database xml.

 

Now add a dataset component to the form from the toolbox. Select the typed dataset.

 

All that's left to do is to create a report and register the data source in it.

Add a button and the Report component from the toolbar.

Double-click on the component report1 to open the report designer. But first, choose a data source applications:

 

Create a simple report with the list in the designer:

 

The list of available data sources can be seen by clicking on the icon (highlighted in red):

 

The window appears:

 

Save the report and return to the application. Add the button click event handler:

1
2
3
4
5
6
 private void button1_Click(object sender, EventArgs e)
 {
 report1.Load(Environment.CurrentDirectory + "/Report.frx");
 report1.RegisterData(demoDataSet1);
 report1.Show();
 }

 Do not forget to add the FastReport library in using. Here we load the report file. Then, register the data source in the report. And run a report in preview mode.

 

RegisterData function allows you to register: DataSet, DataTable, DataView, DataRelation, IEnumerable. The latter one may be a list of objects (including any embedded objects) or, for example, the result of LINQ query. It is important to register the data in the report after loading the report and before viewing or exporting.

Using a data source from the application, it allows us to avoid the need to create a database connection in each report. Besides, if it necessary to change the settings you need edit one connection only.

November 20, 2024

Localization and Language Switching in FastReport VCL

FastReport VCL supports 40 languages for interface localization and allows you to change the language on the fly through menus or code, without recompilation.
November 01, 2024

New Features of the FastReport VCL Editor

We are considering new features of the report editor: extension lines, highlighting of intersecting objects, updated report and data trees.
October 30, 2024

Using Styles When Creating Reports in FastReport VCL

The article discusses one of the new features of FastReport VCL — the use of styles and style sheets.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.