当记录存在时,ADODB 记录集始终 EOF 和 BOF 为 True

问题描述 投票:0回答:2

我有下一个关于 Visual Basic 6 的代码:

Static cmd As ADODB.Command
Static rs As ADODB.Recordset
If cmd Is Nothing Then
 Set rs = New ADODB.Recordset
 rs.ActiveConnection = conn
 Set cmd = New ADODB.Command
 cmd .ActiveConnection = conn
 cmd .CommandText = mySqlCommand
 cmd .Prepared = True
 AddParam cmd, "MyParam", myParam
End IF
SetParam cmd, "MyParam", myParam
rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
While Not rs.EOF
 'Some code...
 '...
 rs.MoveNext
Wend
rs.Close

我完全确定我的命令有结果行。我尝试记录 sql 命令,然后将其复制粘贴到 sqltalk 中,它的工作原理完全符合我的预期 - 它有一行。

但就我而言,在 VB 中,EOF 和 BOF 始终 = True。

为什么?以及如何解决这个问题?

vb6 adodb
2个回答
0
投票

请检查记录集和连接对象的属性cursorLocation。我希望这能解决您的问题。


0
投票
While (rsSource.eof = False) And (StopOrShoot = False)

  ' bookmark must have less value that recordcount for use the command .movenext 
  ' if have the same value and you use .movenext EOF gonna be TRUE and you can´t 
  ' read the last row.... 
  ' you try it ...

  If rsSource.RecordCount > rsSource.Bookmark Then
   rsSource.MoveNext   
  Else
    StopOrShoot = True
  End If
Wend

好看...

G。哥斯达黎加的卡塞雷斯

© www.soinside.com 2019 - 2024. All rights reserved.