Use this method to insert a new record to the recordset. Attempting to insert a record that already exists in the recordset generates an error. To update an existing record, use BBjRecordSet::update. After calling this method, the current record is unchanged. That is to say after inserting a record, you must seek to that newly inserted record before attempting to update. Note that the inserted record may not be visible within the recordset if, for instance, the select statement would not have included it in the original result set.
Example
REM ' Insert a new RecordData to a RecordSet
REM ' First, create a data file
FILENAME$="BBjRecordSet.dat"
MODES$=""
TEMPLATE$="STATE:C(2),NAME:C(16*=)"
erase FILENAME$,err=*next
mkeyed FILENAME$,[0:1:2],0,32
channel=unt
open (channel)FILENAME$
dim REC$:TEMPLATE$
REM ' Load the file with state codes and names
while 1
dread rec.state$,rec.name$,END=*break
write record (channel)rec$
wend
close (channel)
REM ' Create a file-based BBjRecordSet
RecordSet! = BBJAPI().createFileRecordSet(FILENAME$,MODES$,TEMPLATE$)
REM ' Get an empty RecordData
RecordData! = RecordSet!.getEmptyRecordData()
REM ' Set the state code and name
RecordData!.setFieldValue("state","AT")
RecordData!.setFieldValue("name","Atlantis")
REM ' Print the RecordData
print "The new RecordData is:",'LF',RecordData!,
REM ' Write the changes out to disk
RecordSet!.insert(RecordData!)
print "Wrote the new RecordData to disk."
REM WE MUST MOVE TO NEW RECORD BEFORE DOING UPDATES to it.
RecordSet!.seek(RecordData!,1)
RecordData! = RecordSet!.getCurrentRecordData()
RecordData!.setFieldValue("name","Atlantis Proper")
RecordSet!.update(RecordData!)
print "Updated new record, AFTER moving to it."
stop
DATA "AK","Alaska"
DATA "AL","Alabama"
DATA "WI","Wisconsin"
DATA "WV","West Virginia"
DATA "WY","Wyoming"