How to: Populate Worksheets with Data from a Database
| Note | Required applications |
|---|---|
|
The features in this topic are available only if you have the required applications installed. For more information, see Features Available by Product Combination. |
|
Data access works the same way in Microsoft Visual Studio 2005 Tools for the Microsoft Office System projects as it does in Windows Forms projects. You use the same tools and code to bring the data into your solution, and you can even use Windows Forms controls to display the data. In addition, you can take advantage of controls called host controls, native objects in Microsoft Office Excel 2003 that have been enhanced with events and data binding capability. For more information, see Host Items and Host Controls Overview.
To populate a worksheet with data from a database
-
Open your Excel application in Visual Studio, with the worksheet open in the designer.
-
Open the Data Sources window and create a data source for your project. For more information, see How to: Connect to Data in a Database.
-
Drag the table or field you want from the Data Sources window to your worksheet. By default, a NamedRange control is created on the worksheet for each individual field, and a ListObject control is created for each data range that includes multiple rows and columns. You can change this default by selecting the table or field in the Data Sources window and then choosing a different control from the drop-down list.
When you run the project, the controls display the first record in the data source. You can enable scrolling through the records by handling events using the objects in the BindingSource.
See Also
Tasks
How to: Populate Documents with Data from ObjectsHow to: Populate Documents with Data from a Local Database File
How to: Populate Worksheets with Data from Web Services
How to: Update a Data Source with Data from a Host Control
Concepts
Data Sources OverviewDisplaying Data Overview