ComponentOne True DataControl 8.0
DataWrite Event

 

DataWrite Event

Occurs immediately before saving changed values to the data source.

Syntax

TData_DataWrite (Bookmark As Variant, Values As Variant, ByVal NewRow As Boolean, ByVal Update As Boolean, Done As Boolean, Cancel As Boolean)

Remarks

Arguments: Bookmark indicates the row that is going to be saved in the data source.

Values is an array of field values being saved. It is a one-dimensional array indexed with an integer number from 0 to TData.Fields.Count. Values(n) represents the modified value of the n-th field in the TData control. If Value(n) is Empty variant, that means that the n-th field is unchanged, its value is not going to be modified in the data source.

NewRow indicates whether this row is a new row that is being added to the data source (NewRow=True) or a row that already exists in the data source is being modified (NewRow=False).

Update indicates whether this row is written to the data source (Update=True, when an existing row is modified or a new row is written to the data source), or to an internal buffer (Update=False, when a field is being modified, before update to the datasource, or when a new row is created but is not yet updated to the data source).

Done is a flag that can be set to True if you want to override the default action, saving of the row in the data source. If you set Done to True in the event procedure, TData does not modify the data source assuming you have already done what is needed in the event procedure. The Done flag can only be set if Update=True. If Update=False, TData is not saving changes in the data source, so it ignores the Done flag, does not allow you to override the action.

Cancel is a flag that can be set to True to indicate an error condition. You can set it to True either to reject the field values presented for update, due to some validation rule violation, or, if you override TData action by setting Done=True, to inform TData that an error has occurred when you tried to save data.

The DataWrite event allows the developer to modify field values before they are stored in the data source. It can be used for two different purposes:

·      Storing field values differently from how they are presented to the user (in conjunction with DataRead). To do that, change values in the Values array to those that you want to be written to the data source. If Update=True, then even if a field’s value has not been changed by the user (the corresponding Value element is Empty), you can set that Value element thus making TData modify that field’s value in the data source.

·      Overriding the default action of saving changes to the database, if some more involved action than just updating a recordset record is needed.

It is important to understand that changes made in DataWrite are not reflected in TData fields and expressions. They are only applied to the values written to the data source, they do not persist in TData control in any way.

For more information, see Modifying Field Values Retrieving and Saving Them in the Data Source.

See Also

TData Control

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback