行集不支持向后滚动



我试图查询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

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

adOpenDynamic没有在VBScript中声明,因此等于Empty,当您分配CursorType属性时,它被转换为0
0adOpenForwardOnly, forward方法不支持向后移动,而Find方法需要向后移动。

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

Recordset.CursorType = 2 'adOpenDynamic

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

这是因为行集不允许向后移动;如错误信息所示。你的代码没有使用它们;所以你应该替换行

记录集。CursorType = adOpenDynamic与记录集。CursorType=adOpenForwardOnly(或等价值0)

最好完全离开这一行;默认为前向游标。

最新更新