Here is how you can create a report using report components in the visual studio environment. During this, the data is taken from a typed source.
· create a Windows Forms Application project;
· add into it data source (in menu"Data|Add New Data Source...");
· switch to the form designer;
· add the DataSet component from the "Data" category, onto the form and connect it to the typed data source, which you have created.
In order to create the report, do the following:
· place the Report component on the form:
· right click the component , or click the "smart tag" button and, select "Design Report...":
· you will be asked to select the data source for the report. Select the needed table (one or several):
· create the report. You can read more about this in the "Users manual ";
· close the report designer;
· add a Button on the form and double click it;
· in the event handler, write:
report1.Show();
· save the project and run it. When clicking on the button, the report will be built.
This method has got some shortcomings. Firstly, in Visual Studio design-time, you are denied the ability to work with "Live" data. This especially affects working with ASP.NET, and also using business objects as data. This implies that viewing the created report can be done only by running your application.
Secondly, methods of working and saving reports are not optimal. For every report, a different report component needs to be created, reports are saved in application's resource. This can be a problem if there are many reports in your application. However, this lacking can be easily circumvented:
1. Create a report written in the above method;
2. In the report designer, click the "Save" button and save the report in a file;
3. Delete the report component from the form;
4. Use the following code to load and run the report:
using (Report report = new Report())
{
report.Load("your_report.frx");
report.RegisterData(dataSet1, "dataSet1");
report.Show();
}
Here, you can register data by using the report.RegisterData method. Need to indicate the data source, which was used when creating the report (DataSet or BindingSource), and its name ?s well.