Creating a Data-Bound Customized Spreadsheet with VSTO
Creating a no-frills data-bound customized document using the VSTO designer requires no coding but a whole lot of mouse clicking. What we are going to do is first tell Visual Studio about a data sourcein this case, the Northwind sample database that comes with Officeand then drag and drop some data-bound controls onto the spreadsheet.
Defining a Data Source
Let's start up Visual Studio and create a new Excel project. From Visual Studio's Data menu, choose Show Data Sources to display the Data Sources pane. Click Add New Data Source to start the Data Source Wizard.
Figure 17-1. Starting up the Data Source Wizard.
[View full size image]

Figure 17-2. Starting up the Data Source Wizard.
[View full size image]

Figure 17-3. Creating the database connection.

In a real-world application with a secured database, it would be a very bad idea to have a blank administrator password. See the section "Data Sources and Security Best Practices" later in this chapter for more information. |
Figure 17-4. Viewing the connection string.
[View full size image]

Figure 17-5. Save the connection string in the application configuration file.

Figure 17-6. Choose your tables.

Creating Data-Bound Controls the Easy Way
The Data Sources window now contains an entry for the NorthwindDataSet. (Why dataset rather than database ? We explain what exactly we mean by dataset later on in this chapter.) Expand the nodes in the tree view.
Figure 17-7. The Data Sources pane contains the dataset tree view.
[View full size image]

Figure 17-8. Choosing the control type.
[View full size image]

Figure 17-9. Creating the data-bound view.
[View full size image]

Figure 17-10. A data-bound master-detail spreadsheet.
