1

我是 VBScript 的新手,我遇到了以下问题。我想从 sql server db 获取数据并允许 RecordCount 属性。下一个代码获取数据,但 RecordCount 被禁用。如何启用此属性

Const DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=BUG\SQLSERVER2005;Initial Catalog=test;user id ='sa';password='111111'"
Set myConn = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command" )
myConn.Open DB_CONNECT_STRING
Set myCommand.ActiveConnection = myConn
myCommand.CommandText = ("select * from klienci k where k.indeks = " & oferty(16))
Set klienci = myCommand.Execute
4

2 回答 2

0

AFAIK 使用对象的Execute方法时Command无法更改游标类型,检索记录集后也无法更改游标类型。不过,这样的事情可能会奏效:

Const DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=BUG\SQLSERVER2005;Initial Catalog=test;user id ='sa';password='111111'"

Set myConn = CreateObject("ADODB.Connection")
myConn.Open DB_CONNECT_STRING

query = "select * from klienci k where k.indeks = " & oferty(16)

Set klienci = CreateObject("ADODB.Recordset")
klienci.CursorLocation = 3 'adUseClient
klienci.CursorType     = 3 'adOpenStatic
klienci.LockType       = 1 'adLockReadOnly

klienci.Open query, myConn
于 2013-04-23T21:17:23.637 回答
0

I don't think this is a VBScript issue- I think it is an ADO issue.

I think you are using a default forward-only cursor which won't work with recordcount.

I think you should stick a cursortype=adOpenStatic in there but I'm having a little trouble determining if you are specifying a recordset object - klienci?

If so try klienci.cursortype=adOpenStatic

于 2013-04-23T15:20:19.250 回答