I find that you often need to create and manipulate standalone rowsets. Sometimes you can get the data for your standalone rowset from the database using the
Fill method, however sometimes you'll want to copy from existing rowsets. This is where the
CopyTo method comes in handy.
However there is one important thing to note when using
CopyTo - it will only copy like-named record fields and subscrolls at corresponding levels.
In order to work correctly, the record in the source rowset must have the same name as the record in target rowset, unless you specify a record list in the parameters.
For instance, say I have data in a rowset
&rsExample with one record,
EXAMPLE which is populated in the component buffer.
EXAMPLE record has the following fields:
Now, say I want to copy the data from my rowset
&rsExample to another rowset,
&rsExampleAudit which consists of an audit record for
AUDIT_EXAMPLE which has the following fields:
What I want is to copy the like-name fields between
&rsExampleAudit (the fields
The following code will NOT work:
&rsExample consists of a record named
&rsExampleAudit consists of a record named
AUDIT_EXAMPLE. Because the two rowsets do not have the same underlying record name, the copy does absolutely nothing (quite frustrating!).
In this scenario, we need to specify a record list, so it knows the source and target record names. This how I to write this code to make it work:
&rsExample.CopyTo(&rsExampleAudit, Record.EXAMPLE, Record.AUDIT_EXAMPLE)
Generically the syntax is therefore:
&rsSource.CopyTo(&rsTarget, Record.SOURCE_RECNAME, Record.TARGET_RECNAME)