このメソッドは、新しい LCField オブジェクトを作成し、フィールドリスト内の既存フィールドを上書きします。既存フィールドのデータは新しいフィールドにコピーされません。
LCFieldlist
Set newField = fldLstRecord. Replace (index, fieldName, dataType)
パラメータ |
説明 |
---|---|
index |
Long、1 以上。置き換えられるフィールドの、インデックスで指定された位置です。 |
fieldName |
String 型。新しいフィールドの名前です。 |
dataType |
Long。新しいフィールドに割り当てられるデータ型です。 |
値 |
説明 |
---|---|
newField |
LCField。新しいフィールドです。 |
フィールドリスト内のフィールドを置き換えても、フィールドリストに関連付けられたメタデータには影響しません。例では、このメソッドを使用して、既存のテーブルから取り出したフィールドの名前を変更しています。この変更内容は、プログラム内のフィールド名およびデータ型にのみ反映されます。
この例が動作するのは、位置によってフィールドをマッピングするように (デフォルト) コネクションが設定されているためです。MapByName プロパティが True に設定されている場合は、フェッチオペレーションを行ったとき、名前が変更されたフィールドには名前の異なるフィールドの値は挿入されません。詳しくは、Fetch メソッドを参照してください。
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
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