[]
In a Section report, in order to display only the top N number of rows or records on a report, you can manipulate the data in query, or use script depending on the data source. Let's see the working example for a report bound to an Sqlite data source. Your data will be more meaningful if you also specify the order of rows.
Create a new Section report and bind the data to 'reels.db'. See Configure ActiveReports using Config file topic for more information. The data source connection string will be as follows:
data source = C:\Data\reels.db
2. In the Report Data Source dialog, paste the following SQL query in the Query field to fetch Top 10 records from the database, ordered by user rating from highest to lowest:
### Sqlite
```sql
SELECT * FROM Movie Order By UserRating Desc LIMIT 10
```
Then click OK to close the dialog.
In the Report Explorer, expand the Fields node, then the Bound node.
Drag and drop the following fields onto the detail section and set the properties of each textbox as indicated.
[Title]
[YearReleased]
[UserRating]
Drag-drop a Label controls in the PageHeader section for labeling the details in the Detail section, and for the report heading.
Preview the report. You will notice only 10 number of records displaying in your report. The following image illustrates Top N Report displaying top 10 movie records:
The following sections provide sample queries or script that must be used to obtain top N data for other data sources.
SELECT Top 10 * FROM Movie
//countries/country[position() <= 10]
$.Customers[:10]
int i = 1;
public bool ActiveReport_FetchData(bool eof)
{
return i++ > 10;
}
public void ActiveReport_ReportEnd()
{
i = 0;
}