In the previous article, I wrote a simple example of using ActiveReport for. net. This article will demonstrate how to bind a data source in ActiveReport.
1. Create a chartingTable table with two fields: OnlineUserCount and Project. Generate a DataSet using the wizard and drag and drop the TableAdapter.
2. design the display format in the report designer. Put two labels in the PageHeader: "project" and "online users ". In the Detail area, set DataFiled to Project and OnlineUserCount respectively. During the operation, the two labels show the content of the corresponding fields.
3. You can specify DataSet or DataView as the data source for the report. The following shows how to set a data source for the report:
Use DataSet:
This. chartingTableTableAdapter. Fill (this. dataSet1.ChartingTable );
Rpt. DataSource = this. dataSet1;
Rpt. DataMember = this. dataSet1.ChartingTable. TableName;
Rpt. Run ();
This. viewer1.Document = rpt. Document;
Use DataView:
This. chartingTableTableAdapter. Fill (this. dataSet1.ChartingTable );
DataView dv = this. dataSet1.ChartingTable. DefaultView ;;
Rpt. DataSource = dv;
Dv. RowFilter = "project = '1 '";
Rpt. Run ();
This. viewer1.Document = rpt. Document;
4. You can also use the report designer to specify a data source for the report.
In the header of the Detail part of the Report designer, there is a small icon like a database. Click it and a wizard will appear. Follow the Wizard to connect to the database step by step and define the query.
The preceding example shows how to bind a dataset as a data source. However, an object set is often used as a data source in a project. The next example shows how to display data in an object set in a report.