加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – Rowset不支持向后滚动

发布时间:2020-12-12 16:22:12 所属栏目:MsSql教程 来源:网络整理
导读:我试图用以下代码查询MySQL数据库: 'declare the variables Dim ConnectionDim RecordsetDim SQL'declare the SQL statement that will query the databaseSQL = "SELECT * FROM CUSIP"'create an instance of the ADO connection and recordset objectsSet
我试图用以下代码查询MySQL数据库:
'declare the variables 
Dim Connection
Dim Recordset
Dim SQL

'declare the SQL statement that will query the database
SQL = "SELECT * FROM CUSIP"

'create an instance of the ADO connection and recordset objects
Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")

'open the connection to the database
Connection.Open "DSN=CCS_DSN;UID=root;PWD=password;Database=CCS"

Recordset.CursorType=adOpenDynamic

'Open the recordset object executing the SQL statement and return records 

Recordset.Open SQL,Connection
Recordset.MoveFirst

If Recordset.Find ("CUSIP_NAME='somevalue'") Then
    MsgBox "Found"
Else
    MsgBox "Not Found"
End If


'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing

每当我执行上面的操作时,我得到一个错误’rowset不支持向后滚动’,有什么建议吗?

解决方法

adOpenDynamic未在VBScript中声明,因此等于Empty,在分配CursorType属性时会转换为0.
0是adOpenForwardOnly,而forward只支持向后移动,这是Find方法想要的一种能力.

您应该将adOpenDynamic替换为其文字值:

Recordset.CursorType = 2 'adOpenDynamic

要完全避免这类错误,请将Option Explicit作为脚本的第一行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读