To display only the top ten (or other number) of details on a report, you can manipulate the data pulled by your SQL query.
To set an Access data source to pull top ten data
- Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
- On the OLE DB tab, next to Connection String, click the Build button.
- In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
- Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to close the window and fill in the Connection String field.
- In the Query field, paste the following SQL query.
SQL Query |
Copy Code |
SELECT TOP 10 Customers.CompanyName, Sum([UnitPrice]*[Quantity])
AS Sales
FROM (Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID)
INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID
GROUP BY Customers.CompanyName
ORDER BY Sum([UnitPrice]*[Quantity])
DESC
|
- Click OK to return to the report design surface.
To add controls to display the top ten data
- In the Report Explorer, expand the Fields node, then the Bound node.
- Drag the following fields onto the detail section and set the properties of each textbox as indicated.
Field |
Text |
Location |
Miscellaneous |
CompanyName |
Company Name |
0.5, 0 |
|
Sales |
Sales |
5, 0 |
OutputFormat = Currency |
|
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. |
See Also