The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Accessing Data Sample

Download sample

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.

  • One of these development environments:

    VSTO 2005


    Visual Studio Team System

  • Microsoft Office 2003

This sample demonstrates how to read data from a data source and display it in a Microsoft Office Excel 2003 worksheet or Microsoft Office Word 2003 document.

The sample contains an Excel Workbook project and a Word Document project. Each project document has an actions pane that displays a set of option buttons, each of which represents a different data source. When you select an option, data from that data source are displayed in the document.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

For information about installing the sample project on your computer, see How to: Download Sample Files in Help Topics.

To run this sample

  1. Install the SQL Server database that the sample uses.

    1. In the Accessing Data Database Initialization project, open the Create Scripts folder.

    2. Right-click the file Create Accessing Data SQL Database.sql.

    3. Click Run on the shortcut menu.

      The script creates a SQL Server database named AccessingData.

      Caution noteCaution

      If you already have a database named AccessingData in SQL Server, this script will replace the existing database and your data will be lost.

  2. Press F5.


For full functionality, this sample requires:

  • SQL Server installed on the local computer, with the database that is included in the sample.

  • A Microsoft Office Access 2003 database that is included in the sample.

  • The AccessingDataWebService Web service that is included in the sample.


This sample demonstrates several types of data access and display:

  • How to read data from a comma-delimited text file, an XML file, an Access database, a SQL Server data table, a SQL Server stored procedure, and a Web service.

  • How to populate a Word document and an Excel worksheet with data from a data source.

  • How to write data to ListObject controls.

  • How to write data to NamedRange controls.

  • How to write data to Bookmark controls.

The Excel sample includes a worksheet that contains a ListObject control and two NamedRange controls. When you select a data source, data is inserted into the controls on the worksheet.

The Word sample consists of a document that contains two Bookmark controls. When you select a data source, data is inserted into the controls on the document.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft