Data Access Modes > Data Source Mode > Setting SourceRecordset and DataSource at Run Time |
As an alternative to setting up the SourceRecordset at design time with True DataControl data source properties or DataSource/DataMember properties, you can set it at run time to any ADO recordset. The normal place to do this is the OpenData event. For more information, see Events in creating recordset at run time.
Bear in mind that the OpenData event is called on each refresh, as well as during startup. A TData control is refreshed when the Refresh method is called, or when changes occur in the Master TData control, in a True DataControl parameter, or in one of the True DataControl collections.
If you do not want to set up the recordset at design time, leave all True DataControl data source properties empty and set the SourceRecordset property to a valid ADO recordset in the OpenData event. You also have an alternative to setting SourceRecordset: you can also set the DataSource/DataMember properties to an existing ADO/OLE DB data source, such as an ADODC control or DataEnvironment.
As for specifying True DataControl fields in this case, you have two options:
Leave the Fields property page empty; do not specify any fields. The fields will be retrieved from SourceRecordset. Field retrieval also occurs if you empty the collection returned by the Fields property within the WillOpenData event.
Create all necessary fields manually in the Fields page or in code in WillOpenData event. Create each field as a data field (select the Data radio button) and specify its Name and DataSourceField property.
When SourceRecordset or DataSource is set from code, the existing True DataControl fields are verified against the new SourceRecordset. Some of them might not exist in the new SourceRecordset, in other words, their DataSourceField property does not correspond to any field in the new SourceRecordset. Such fields become unavailable after refresh.
You can also set the SourceRecordset property (also DataSource/DataMember properties) from code outside of True DataControl events. This will cause a refresh of the TData control, because its recordset needs to be rebuilt (you can use the ChangeInProgress property to postpone the refresh).
Note: The SourceRecordset property is unavailable in True DataControl Lite. Use DataMember/DataSource instead. |