Insert Method for LCConnection

This method inserts a specified number of records into the connection metadata. For example, this method inserts one or more records into the defined METADATA object in DB2®.

Note: You can achieve optimal performance by using the same fieldlist across consecutive inserts from the same target.

Defined In

LCConnection

Syntax

count = lcConnection.Insert(srcFieldlist, recordIndex, recordCount)

Parameters

Parameter

Description

srcFieldlist

LCFieldlist. Fieldlist containing the records to insert. For each field in Fieldlist without the flag LCFIELDF_NO_INSERT, data from the corresponding field in the result set will be copied into that field. Fields in the result set and fieldlist are matched by name if the MapByName property is TRUE, by position otherwise, and are type-checked before inserting data.

recordIndex

Long. Optional, >=1. Starting record index of the insert in the fieldlist. The default is 1.

recordCount

Long. Optional, >=1. Number of records to insert. The number of records actually inserted may be less than this number if an error was encountered. While all connectors can insert multiple records, only connectors that indicate support for Array Insert perform a true multi-record insert and therefore reduce network traffic and increase performance. The default is 1.

To use the recordCount parameter to write multiple records, or to use a recordIndex greater than 1, you must supply a destFieldList that has been allocated to contain multiple rows of data. Refer to the New method of LCFieldlist for details.

Return Value

Value

Description

count

Long. Number of records successfully inserted.

Usage Notes®

If there is an error midway through a multiple record insert operation, an error event will occur. The changes up to that point will not be committed, and you should use the Action method to rollback or commit.

Example

Option Public
Uselsx "*lsxlc" 

Sub Initialize
  Dim src As New LCConnection ("db2") 
  Dim fields As New LCFieldList (5)
  Dim field As LCField
  Dim data(4) As String
  Dim idata(4) As Long

  ' set the appropriate properties to connect to the data sources
  src.Database = "Gold"
  src.Userid = "JDoe"
  src.Password = "xyzzy"
  src.Metadata = "customer"
  src.MapByName = True
  ' connect to the two data sources
  src.Connect

  ' use a key to find certain records to remove
  Set field = fields.Append ("ACCOUNTMANAGER", LCTYPE_INT)
  idata(0) = 100
  idata(1) = 200
  idata(2) = 300
  idata(3) = 400
  idata(4) = 500
  field.value = idata
  Set field =  fields.Append ("CONTACTNAME", LCTYPE_TEXT)
  data(0) = "Peter Pan"
  data(1) = "Big Steel"
  data(2) = "R. U. Happy"
  data(3) = "Isaac Bernard Mathews"
  data(4) = "Paula Falderall"
  field.value = data
  Set field = fields.append ("COMPANYADDRESS", LCTYPE_TEXT)
  data(0) = "One Bit Tree"
  data(1) = "Gurder Way"
  data(2) = "Daisy Hill Pup Farm"
  data(3) = "Big Blue Ave."
  data(4) = "Planet Holly"
  field.value = data
  Set field = fields.Append ("COMPANYCITY", LCTYPE_TEXT)
  data(0) = "Never Never"
  data(1) = "Iron"
  data(2) = "Beagle"
  data(3) = "New York"
  data(4) = "Parthenon"
  field.value = data
  Set field = fields.Append ("COMPANYSTATE", LCTYPE_TEXT)
  data(0) = "Land"
  data(1) = "PA"
  data(2) = "WI"
  data(3) = "NY"
  data(4) = "AQ"
  field.value = data
  ' Create new records from the five records in the fieldlist.
  Print "Inserted " & Cstr (src.Insert (fields, 1, 5)) & " record(s)."
End Sub

Example Output

Inserted 5 record(s).