Accessing and manipulating data in a DataStore

To access data using a DataStore, you need to read the data from the data source into the DataStore.

If the data source is a database

If the data for the DataStore is coming from a database (that is, the data source was defined as anything but External in the DataWindow painter), you need to communicate with the database to get the data. The steps you perform to communicate with the database are the same steps you use for a DataWindow control.

For more information about communicating with the database, see “Accessing a database”.

If the data source is not a database

If the data for the DataWindow object is not coming from a database (that is, the data source was defined as External in the DataWindow painter), you can use the following methods to import data into the DataStore:

You can also get data into the DataStore by using a DataWindow data expression or by using one of the SetItem methods.

For more information about the SetItem methods, see “Accessing data values using methods”.

About the DataStore buffers

Like a DataWindow control, a DataStore uses three buffers to manage data:

Table 4-1: DataStore buffers

Buffer

Contents

Primary

Data that has not been deleted or filtered out (that is, the rows would be visible in a visual presentation)

Filter

Data that was filtered out

Delete

Data that was deleted by the user or in a script

Programming with DataStores

There are many methods for manipulating DataStore objects. These are some of the more commonly used:

Table 4-2: Common methods in DataStore objects

Method

Purpose

DeleteRow

Deletes the specified row from the DataStore.

Filter

Filters rows in the DataStore based on the current filter criteria.

InsertRow

Inserts a new row.

Print

Sends the contents of the DataStore to the current printer.

Reset

Clears all rows in the DataStore.

Retrieve

Retrieves rows from the database.

RowsCopy

Copies rows from one DataStore to another DataStore or DataWindow control.

RowsMove

Moves rows from one DataStore to another DataStore or DataWindow control.

ShareData

Shares data among different DataStores or DataWindow controls. See “Sharing information”.

Sort

Sorts the rows of the DataStore based on the current sort criteria.

UpdateData

Sends to the database all inserts, changes, and deletions that have been made since the last UpdateData.

For information about DataStore methods, see the online Help in Visual Studio.

Dynamic DataWindow objects The methods in the table above manipulate data in the DataStore but do not change the definition of the underlying DataWindow object. In addition, you can use the Describe and Modify (or GetProperty and SetProperty) methods to access and manipulate the definition of a DataWindow object. Using these methods, you can change the DataWindow object at runtime. For example, you can change the appearance of a DataWindow or allow your user to create ad hoc reports.

For more information, see Chapter 7, “Dynamically Changing DataWindow Objects.”

Using DataStore properties and events This chapter mentions only a few of the properties and events that you can use to manipulate DataStores. For more information about DataStore properties and events, see the online Help.