Replace Method for LCFieldlist

This method creates a new LCField object and puts it into the fieldlist in place of an existing field. The data from the old field is not copied into the new field.

Defined In

LCFieldlist

Syntax

Set newField = fldLstRecord. Replace (index, fieldName, dataType)

Parameters

Parameter

Description

index

Long, >1. The index position of the field to replace.

fieldName

String. The name of the new field.

dataType

Long. The data type to assign to the new field.

Return Value

Value

Description

newField

LCField. The new field.

Usage Notes®

Replacing a field in a fieldlist does not affect the metadata associated with the fieldlist. In the example, the method is used to change the name of a field retrieved from an existing table. This change affects the field name and data type only within this program.

This example works because the connection is set to map fields by position (the default). If the MapByName property were set to True, the Fetch operation would not fill in the renamed field with a value from a field that has a different name. See the Fetch method for details.

Example

Option Public
Uselsx "*lsxlc" 
Sub Initialize
  Dim connect As New LCConnection ("db2") 
  Dim FldLst As New LCFieldlist
  Dim field As LCField
  Dim text As String
  REM this section assigns the appropriate properties to connect to DB2
  connect.Database = "Gold"
  connect.Userid = "JDoe"
  connect.Password = "xyzzy"
  connect.Metadata = "customer"
  REM connect to DB2
  connect.Connect
  REM Select all records in the customer table
  If (connect.Select (Nothing, 1, FldLst) = 0) Then
    Print "The customer table was not found."
  Else
    REM FldLst contains the list of fields in the table, but no values 
    REM until the Fetch
    Call FldLst.Replace (2, "pinky", LCTYPE_TEXT)
    text = ""
    Forall fieldname In FldLst.Names
      If (text = "") Then text = fieldname Else text = text + ", " + fieldname
    End Forall
    Print "The new list of columns in the '" & connect.Metadata & "' table are: " & text
    If connect.Fetch(FldLst) Then
      REM if there's any data in the table, display the values in 
      REM the first row
      Dim i As Long
      text = ""
      For i = 1 To FldLst.Fieldcount
        text = text & " " & FldLst.GetName(i) & "=" & _
        FldLst.GetField(i).Text(0)
      Next
      Print text
    End If
  End If
End Sub

Example Output

The new list of columns in the 'customer' table are: ACCOUNTMANAGER, pinky, COMPANYNAME, COMPANYADDRESS, COMPANYCITY, COMPANYSTATE, COMPANYPHONE
ACCOUNTMANAGER=Tina Jenson pinky=John Darmain COMPANYNAME=Darmain Pharmaceuticals COMPANYADDRESS=12 Darmain Circle COMPANYCITY=Topeka COMPANYSTATE=KS COMPANYPHONE=605-555-2000