为什么我在第一次提取后收到字段计数不匹配错误?

Why am I getting a Field Count Mismatch error after the first Fetch?

我已经尝试了所有我能想到的方法,但我仍然在 Fetch 上遇到错误

我正在为每个 Select 语句遍历一个多值字段,并且需要将 return 值存储在另一个多值字段中。它适用于第一个循环,然后在第二次获取时出错。

If lc_conn.IsConnected Then     
    For a = 0 To UBound(uniquePlans)            
        b = 0
        SelectStatement2 = "Select Count(CSSN) as counter From cbsdta.covgold where " &_
        " CEFFDT<" & todaysDate & " And (CTRMDT=0 Or CTRMDT>=" & todaysDate & ") And " &_
        "CDTASRC='GIAS' AND CABSGP='" & groupNo & "' AND CPRODTA='" & uniquePlans(a) & "'"
        
        Count2 = lc_conn.Execute(SelectStatement2, fldLstRecord2 )
        if Count2 <> 0 then

            While (LC_Conn.Fetch( fldLstRecord2 ) > 0) '<---- Error here on 2nd loop

                redim Preserve CoveredLives(b)
                Set CoveredLives(b) = fldLstRecord2.Lookup("counter").value
                b = b + 1
            Wend
        End if
    Next
    doc.CoveredLives = CoveredLives
End If

感谢所有想法或建议

根据 HCL 文档中的 exampleLookupFetch 循环之外使用。试试这个:

       Dim fieldCounter As LCField
...

       Set fieldCounter = fldLstRecord2.Lookup("counter")
       While (LC_Conn.Fetch( fldLstRecord2 ) > 0) 
            redim Preserve CoveredLives(b)
            Set CoveredLives(b) = fieldCounter.value(0)
            b = b + 1
       Wend

LCField 的 value returns 始终是一个值数组,因此您应该使用 .value(0).

事实证明,我需要在循环中使用“删除 fldListRecord2”命令来清除 fldListRecord2。一旦我添加了它,一切正常。我还必须在循环中调暗 LCFieldList,以便每次重新初始化它。

If lc_conn.IsConnected Then
    ReDim Preserve CoveredLives(UBound(uniquePlans))        
    For a = 0 To UBound(uniquePlans)
        Dim fldLstRecord2 As New LCFieldList            
        If (lc_conn.Execute ("Select Count(CSSN) as counter From cbsdta.covgold where " &_
        " CEFFDT < " & todaysDate & " And (CTRMDT = 0 Or CTRMDT > " & todaysDate & ") And " &_
        "CDTASRC = 'GIAS' AND CABSGP = '" & groupNo & "' AND CPRODTA = '" & Right(uniquePlans(a),7) & "'", fldLstRecord2) <> 0) Then            
        End If          
        Set fld = fldLstRecord2.Lookup ("counter")
        While (lc_conn.Fetch(fldLstRecord2) > 0)                
            CoveredLives(a) = fld.text(0)                
            Delete fldLstRecord2
        Wend            
    Next        
    doc.CoveredLives = CoveredLives     
End If

谢谢你的想法