If rptReduct1.State = adStateOpen Then rptReduct1.Close
  rptReduct1.Open "select id from employee", dbConnect, adOpenDynamicFor intI = 0 To rptReduct1.RecordCount - 1
  rptReduct1.Fields("reduct").Value = 0
  rptReduct1.MoveNext
 Next intI
当执行的时候,总是跳过FOR循环,调试的时候说我的总说我的rptReduct1.RecordCount的值为-1,而我的数据库id字段确实有20个值,不知道这是为什么清各位帮忙解答!100分相送!

解决方案 »

  1.   

    用rptReduct1.RecordCount得到记录总数有时会产生错误,试试下面的函数:
    '作用:取记录集的记录数
    '参数:rec 记录集对象
    '返回:记录集的记录数
    Private Function RecordCount(ByVal rec As ADODB.Recordset) As Integer
    Dim i As Integer
    If rec.EOF Then
    RecordCount = 0
    Exit Function
    End If
    With rec
    .MoveFirst
    Do While Not .EOF
    i = i + 1
    .MoveNext
    Loop
    .MoveFirst
    End With
    RecordCount = i
    End Function
      

  2.   

    rptReduct1.Open "select id from employee", dbConnect, adOpenStatic, adLockOptimistic
       If rptReduct1.RecordCount > 0 Then
          rptReduct1.MoveFirst
          Do Until rptReduct1.EOF
             LisCusNO.AddItem rptReduct1.Fields("reduct") = 0
             rptReduct1.MoveNext '下一个
          Loop
       End If
      

  3.   

    你rptReduct1的游标设置好没有?.....
      

  4.   

    还一个错误
    select id from employee", dbConnect, adOpenDynamicrptReduct1.Fields("reduct").Value = 0----你选择的时候只选择了ID字段.没有reduct字段
      

  5.   

    rptReduct1.Open "select id from employee", dbConnect, adOpenStatic, adLockOptimistic
       If rptReduct1.RecordCount > 0 Then
          rptReduct1.MoveFirst
          Do Until rptReduct1.EOF
             LisCusNO.AddItem rptReduct1.Fields("reduct") = 0
             rptReduct1.MoveNext '下一个
          Loop
       End If
      

  6.   

    If rptReduct1.State = adStateOpen Then rptReduct1.Close
      rptReduct1.Open "select id from employee", dbConnect, adOpenDynamicFor intI = 0 To rptReduct1.RecordCount - 1
      rptReduct1.Fields("reduct").Value = 0
      rptReduct1.MoveNext
     Next intI
    以上你取得記錄集只有一個id字段,而你在for循環中,怎麼又跑出來個reduct字段呢.