How to: Cache Data for Use Offline or on a Server
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.
Applies to: The information in this topic applies to document-level projects for Excel and Word. For more information, see Features Available by Office Application and Project Type.
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 a property in the Properties window. If you are caching a data item that is not a DataSet or DataTable, ensure that it meets the criteria for being cached in the document. For more information, see Caching Data.
Declare a public field or property for the data item as a member of a host item class in your project, such as the
ThisDocument class in a Word project or the
ThisWorkbookclass in an Excel project.
Add code to create an instance of the data item and, if applicable, to 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.
Add the dataset to the project by using tools in the Visual Studio designer, for example, by adding a data source to your project using the Data Sources window.
Create an instance of the dataset if you do not already have one, and select the instance in the designer.
In the Properties window, set the CacheInDocument property to True.
For more information, see Properties in Office Projects.
In the Properties window, set the Modifiers property to Public (by default it is Internal).