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 the database”.

If the data source is not a database

If the data for the DataWindow object does not come 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 put data in the DataStore by using a DataWindow data expression, or by using the SetItem method. You can use the same property and data expressions as for a DataWindow control.

For more information on accessing data in a DataStore, see the DataWindow Reference in the online Help.

About the DataStore buffers

Like a DataWindow control, a DataStore uses three buffers to manage data. The buffers are described in Table 11-1.

Table 11-1: DataStore buffers

Buffer

Contents

Primary

Data that has not been deleted or filtered out (that is, the rows that are viewable)

Filter

Data that was filtered out

Delete

Data that was deleted by the user or in a script

About the Edit control

The DataStore object has an Edit control. However, the Edit control for a DataStore behaves in a slightly different manner from the Edit control for a DataWindow. The Edit control for a DataWindow keeps track of text entered by the user in the current cell (row and column); the Edit control for a DataStore is used to manage data imported from an external source. The text in the Edit control for a DataStore cannot be changed directly by the user. It must be manipulated programmatically.

Programming with DataStores

There are many methods for manipulating DataStore objects. Table 11-2 lists some of the more commonly used.

Table 11-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.

Update

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

For information about DataStore methods, see the DataWindow Reference in the online Help.

Dynamic DataWindow objects The methods in Table 11-2 manipulate data in the DataStore but do not change the definition of the underlying DataWindow object. In addition, you can use the Modify and Describe 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.

If you assign a DataWindow object to a DataStore dynamically, you must make sure that the DataWindow object is available in a PKD file or is listed in a PKR file used to create the executable.

For more information, see Chapter 10, “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 DataWindow Reference in the online Help.