This documentation is archived and is not being maintained.

How to: Cache Data for Use Offline or on a Server

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

You can mark a data item to be cached in the document, so that it is available offline. This also makes it possible for the data in the document to be manipulated by other code when the document is stored on a server.

You can mark a data item to be cached when the data item is declared in your code, or, if you are using a DataSet, by setting the property in the Properties window.


Datasets created using Visual Basic that are marked as Cached and WithEvents (including datasets that are dragged from the Data Sources window or Toolbox that have the CacheInDocument property set to True) have an underscore prefixed to their names in the cache. For example, if you create a dataset and name it Customers, the CachedDataItem name will be _Customers in the cache. When you use ServerDocument to access this cached item, you must specify _Customers instead of Customers.

To cache data in the document using code

  1. Declare a public variable for the data item, using the CachedAttribute attribute to mark the data item to be stored in the document:

    public DataSet employeesDataSet;
  2. Add code to create an instance of the data item and load it from the database.

    The data item is only loaded when it is first created; thereafter, the cache stays with the document and you must write other code to update it.

To cache data in the document using the Properties window

  1. Add the dataset to the project using tools in the Visual Studio designer, for example, by adding a data source to your project using the Data Sources window.

  2. Create an instance of the dataset if you do not already have one, and select the instance in the designer.

  3. In the Properties window, set the Cache in Document property to True.

    For more information, see Properties in Visual Studio Tools for Office Projects.

  4. In the Properties window, set the Modifiers property to Public (by default it is Internal).

See Also