ComponentOne True DataControl 8.0
Using the Recordset Property

Whenever you need programmatic access to the underlying data, use the True DataControl’s Recordset property, which returns the ADO recordset object representing the TData control’s data, its recordset.

The Recordset property is read-only, in the sense that you can’t set it to another recordset object. True DataControl has a separate property, SourceRecordset, which can be set to an ADO recordset. Differences between Recordset and SourceRecordset properties are discussed in Data Source Mode.

Most programmatic access to True DataControl is done through its Recordset property. Some typical uses are:

  1. Use Recordset.Bookmark to get the current record bookmark; set Recordset.Bookmark to move the current record to a bookmark.

  2. Call Recordset.AddNew to add records.

  3. Call Recordset.Delete to delete records.

  4. Call Recordset.Update to send changes to the database, or call Recordset.UpdateBatch in batch update mode, that is, if LockType=adLockBatchOptimistic.

See the ADO documentation for complete reference.

True DataControl provides two methods, UpdateFields and CancelUpdate, which complement the standard ADO Recordset functionality.

We recommend using TData.CancelUpdate instead of TData.Recordset.CancelUpdate, because Recordset.CancelUpdate does not revert the value in a bound control until that value is updated to the recordset field.

Call TData.UpdateFields if you need to update the recordset field with the value in a bound control without waiting until the user moves focus out of the bound control or leaves the current record. This functionality is missing in the ADO Recordset.

You can modify data in the current record by setting recordset field values in the following manner:

Example Title
Copy Code
TData1.Recordset(“Amount”) = 10.0

There is nothing wrong with this line, but we suggest an alternative way, provided by the True DataControl Fields property:

Example Title
Copy Code
TData1.Fields(“Amount”).Value = 10.0

or, in abbreviated form:

Example Title
Copy Code
TData1(“Amount”) = 10.0

This is not only shorter than one using Recordset, but it also allows more control, such as setting several fields at once without updating dependencies, using the ChangeInProgress property.

In order to use ADO recordsets in code without restrictions, you must add a reference to the ADODB type library (Microsoft ActiveX Data Objects) to your project.

For better performance, we strongly recommend that you create an object variable for the Recordset object and use it each time to access a method or property. For example, although it is possible to write:

Example Title
Copy Code
TData1.Recordset.UpdateBatch

...

TData1.Recordset.Bookmark = Bmk

it can cause performance degradation, since a recordset object is created and immediately destroyed by every such call. The right way is to define a variable:

Example Title
Copy Code
Dim RS As ADODB.Recordset

and set it in the OpenDataComplete event (fired when the True DataControl’s recordset has been successfully created):

Example Title
Copy Code
Private Sub TData1_OpenDataComplete()

Set RS = TData1.Recordset

End Sub

Then you can use that variable:

Example Title
Copy Code
RS.UpdateBatch

...

RS.Bookmark = Bmk

 

 


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

Product Support Forum  |  Documentation Feedback