6

我正在尝试使用以下代码查询 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

每当我执行上述操作时,我都会收到错误“行集不支持向后滚动”,有什么建议吗?

4

2 回答 2

7

adOpenDynamic未在 VBScript 中声明,因此 equals会在您分配属性时Empty转换为。是,并且 forward only 不支持向后移动,这是该方法想要的一种能力。0CursorType
0adOpenForwardOnlyFind

你应该adOpenDynamic用它的文字值替换:

Recordset.CursorType = 2 'adOpenDynamic

要完全避免此类错误,请将Option Explicit其放在脚本的第一行。

于 2013-01-02T12:53:50.823 回答
0

那是因为行集不允许向后移动。正如错误消息所暗示的那样。您的代码没有使用它们;所以你应该换行

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

最好完全离开;默认为向前光标。

于 2013-01-02T12:50:42.390 回答