行集不支持向后滚动(Rowset does not support scrolling backwa

2019-07-17 18:04发布

我想查询与下面的代码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

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

Answer 1:

adOpenDynamic是不是在VBScript中声明,所以等于Empty ,它被转换为0 ,当你指定CursorType属性。
0adOpenForwardOnly ,并且只转发不支持向后移动的能力Find方法希望。

此时应更换adOpenDynamic其文字值:

Recordset.CursorType = 2 'adOpenDynamic

为了避免这种错误类干脆,将Option Explicit作为脚本的第一行。



Answer 2:

这是因为行集不允许向后移动; 作为错误信息提示。 您的代码不使用它们; 所以你应该更换线

Recordset.CursorType = adOpenDynamic与Recordset.CursorType = adOpenForwardOnly(或等效值0)

最好把线完全; 默认是前进光标。



文章来源: Rowset does not support scrolling backward