Information
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.

How to: Populate Documents with Data from Services

Updated: July 2008

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

Microsoft Office version

  • Excel 2007

  • Excel 2003

  • Word 2007

  • Word 2003

For more information, see Features Available by Application and Project Type.

Data access works the same way in document-level Visual Studio Tools for Office 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, which are native objects in Microsoft Office Excel and Microsoft Office Word that have been enhanced with events and data binding capability. For more information, see Host Items and Host Controls Overview.

Starting in Visual Studio 2008 Service Pack 1 (SP1), you can also access data in application-level projects programmatically at run time.

The following example shows how to add data-bound controls to documents at design time. For an example of how to add data-bound controls in application-level add-ins at run time, see Walkthrough: Binding to Data from a Service in an Application-Level Project.

link to video For a related video demonstration, see How Do I: Interact with Web Services from Microsoft Excel?.

To populate a document-level project with data from a Web service

  1. Open the Data Sources window and create a service data source for your project. For more information, see How to: Connect to Data in a Web Service.

  2. Drag the table or field you want from the Data Sources window to your document.

    A control is created on the document, a BindingSource is created that is bound to the object class in your project, and classes are generated for the service.

  3. In your code, create an instance of the Web service class that you connected to in step 1.

  4. If there are properties that are required for communication with the Web service, create instances of those properties.

  5. Create and send a data request using methods exposed by the Web service and any property instances you created in step 4.

    The methods that you use depend on what the Web service offers.

  6. Assign the data response from the Web service to the DataSource property of the BindingSource.

When you run the project, the controls display the first record in the data source. You can enable scrolling through the records by handling the currency events using the objects in the BindingSource.

Date

History

Reason

July 2008

Added SP1 information.

SP1 feature change.

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

Community Additions

Show:
© 2014 Microsoft