How the DataWindow control updates the database

For database updates, the DataWindow control determines what type of SQL statements to generate by looking at the status of each of the rows and columns in the DataWindow buffers.

For rows, the RowStatus enumeration has four values. For columns, the ItemStatus enumeration has two values.

Table 3-4: RowStatus enumeration

Value

Meaning

New

The row is new but no values have been specified for its columns.

NewAndModified

The row is new, and values have been assigned to its columns. In addition to changes caused by user entry or one of the SetItem methods, a new row gets the status NewModified when one of its columns has a default value.

NotModified

The information in the row has not changed.

Modified

The information in one or more of the columns in the row has changed.

Table 3-5: ItemStatus enumeration

Value

Meaning

NotModified

The information in the column has not changed.

Modified

The information in the column has changed.

How statuses are set

When data is retrieved When data is retrieved into a DataWindow, all rows and columns initially have a status of NotModified.

After data has changed in a column in a particular row, either because the user changed the data or the data was changed programmatically, such as through one of the SetItem methods, the ItemStatus for that column changes to Modified. Once the status for any column in a retrieved row changes to Modified, the RowStatus also changes to Modified.

When rows are inserted When a row is inserted into a DataWindow, it initially has a RowStatus of New, and all columns in that row initially have an ItemStatus of NotModified. After data has changed in a column in the row, either because the user changed the data or the data was changed programmatically, the ItemStatus changes to Modified. Once the ItemStatus for any column in the inserted row changes to Modified, the RowStatus changes to NewAndModified.

When a DataWindow column has a default value, the column’s status does not change to Modified until the user makes at least one actual change to a column in that row.

When UpdateData is called

For rows in the Primary and Filter buffers When the UpdateData method is called, the DataWindow control generates SQL INSERT and UPDATE statements for rows in the Primary and/or Filter buffers based upon the row statuses in Table 3-6.

Table 3-6: RowStatus and SQL statement generated

Row status

SQL statement generated

NewAndModified

INSERT

Modified

UPDATE (or DELETE/INSERT if a primary key is changed and the update properties of the DataWindow object are set to generate that sequence)

A column is included in an UPDATE statement only if the following two conditions are met:

The DataWindow control includes all columns in INSERT statements it generates. If a column has no value, the DataWindow attempts to insert a null. This causes a database error if the database does not allow null values in that column.

For rows in the Delete buffer The DataWindow control generates SQL DELETE statements for any rows that were moved into the Delete buffer using the DeleteRow method. However, if a row has a RowStatus of New or NewAndModified before DeleteRow is called, no DELETE statement is issued for that row.