vba连接Oracle问题

petercow 2007-05-22 06:18:29
vba连接Oracle10g后执行SQL语句,没有数据!代码如下:
Private conConnection As ADODB.Connection
Public rct As New ADODB.Recordset
Set conConnection = New ADODB.Connection
conConnection.ConnectionString = "ODBC;DRIVER={Oracle in OraDb10g_home1};UID=FAIR;PWD=fair;Data Source=fair;Persist Security Info=True"
conConnection.ConnectionTimeout = 30
conConnection.Open
Set rct = conConnection.Execute("SELECT levelID,levelName FROM abilitylevel")
MsgBox "Records:" & rct.RecordCount

执行后,显示的RecordCount为-1,但是用Oracle客户端查询表里是有记录的!该怎么解决阿??请指教,谢谢!
...全文
477 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
李迎春82 2007-06-01
  • 打赏
  • 举报
回复
在conConnection.Open之前加上如下代码:
conConnection.CursorLocation = adUseClient

这个问题我在数据库开发的时候碰到过千百次,敢以性命担保.

楼主不给分就太过份了.
shan1119 2007-05-25
  • 打赏
  • 举报
回复
忘了,学习
沐NeMo 2007-05-23
  • 打赏
  • 举报
回复
显示的RecordCount为-1 表示rct里有记录数据。我也遇到过你这样的问题。
-------
你在select出记录后要先把记录移到最后,再显示记录数,如:
Set rct = conConnection.Execute("SELECT levelID,levelName FROM abilitylevel")
rct.MoveLast
MsgBox "Records:" & rct.RecordCount
就正常。试试。
-------
一般要先判断有没有记录用:
If Not(rct.Eof and rct.Bof) then MsgBox "有记录"

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧