行集不支持向后滚动

Tel*_*lva 5 sql vbscript recordset rowset

我试图用以下代码查询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
Run Code Online (Sandbox Code Playgroud)

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

GSe*_*erg 6

adOpenDynamic未在VBScript中声明,因此等于Empty,0在分配CursorType属性时转换为.
0adOpenForwardOnly,并且前进只是不支持向后移动,Find方法想要的能力.

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

Recordset.CursorType = 2 'adOpenDynamic
Run Code Online (Sandbox Code Playgroud)

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