Udostępnij za pośrednictwem


Accessing Data Sample

Note

This sample runs only in Microsoft Office Excel 2007 and Microsoft Office Word 2007.

This sample demonstrates how to read data from a data source and display it in an Excel worksheet or Word 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 is displayed in the document.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

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.

      Warning

      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.

Requirements

For full functionality, this sample requires the following components:

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

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

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

Demonstrates

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

Concepts

Host Items and Host Controls Overview

Other Resources

Data in Office Solutions

Document-Level Samples