以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  关于VBS中RecordSet的Seek和Find  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=49927)

--  作者:独行
--  发布时间:2013/3/19 15:36:35
--  关于VBS中RecordSet的Seek和Find

请教下客服,在Access的Mdb里,金字塔的VBS是否支持RecordSet记录集的Seek方法?如果支持,应该如何实现?本人测试了好久都没实现。

另外,在使用Find方法时,有时候会出现表里已有数据,但还是定位不了,直接报EOF错误。

多谢!!


--  作者:rushtaotao
--  发布时间:2013/3/19 16:09:58
--  
把你测试代码发出 我们看下
--  作者:独行
--  发布时间:2013/3/19 16:22:37
--  

多谢客服!测试代码如下:

Sub TestSeek

    Set Cnn=CreateObject("Adodb.Connection")
   
    Set Rs=CreateObject("ADODB.Recordset")
    Cnn.Open "Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=E:\\Test.mdb"
    Str="Select * from Table1 Order by StockDate"
    Rs.Open Str,Cnn,1,3
   
    Set Rs1=CreateObject("ADODB.Recordset")
    Rs1.Open Str,Cnn,1,3
    While Not rs1.eof
       vDate=Rs1("StockDate")

       Rs.Seek vDate,1

       if rs.eof then
          msgbox Rs1("Date1")&"  not found.."
       else
         
       End if
       Rs1.MoveNext
    Wend

End Sub


--  作者:独行
--  发布时间:2013/3/19 16:27:51
--  

错误提示:编译器错误  \'3251\'

              当前提供程序不支持"索引"功能必须的界面。


--  作者:王锋
--  发布时间:2013/3/20 9:25:10
--  

这是百度上搜到的信息,希望读你有用

 

The Seek method searches the index of a Recordset to find a record that matches the values specified in the keyvalues parameter. If there is a match, the pointer will point to the record specified by the seekoption parameter. If there is no match, the record pointer will be placed at the end of the Recordset.
Seek的作用是:搜索一个记录集的index[索引],从中查找与keyvalues参数中指定的值相匹配的一条记录。如果找到了匹配对象,那么记录指针将指向seekoption参数指定的记录;如果未找到匹配对象,那么记录指针将定位在记录集的末尾处。

Note: To use this method, the provider must support this method and the use of indexes on a Recordset (the Index property). Use the Supports method to determine whether the provider supports seek and indexes.
注意:使用这个方法的前提是:技术提供对象[provider]必须支持这个方法,并且必须在一个记录集参数(索引[index]属性中)中使用索引[index];使用Supports方法可以用来确定技术提供对象[provider]是否支持Seek和index方法。

Note: Set the Index property to the desired index before executing this method.
注意:必须在这个方法执行之前将index属性设置为你希望的index值。

Note: This method can only be used with server-side cursors (not supported when the CursorLocation property value is adUseClient).
注意:这个方法只能用于服务器端的记录指针(当CursorLocation属性值为adUseClient时,则不能获得支持)。

Note: This method can only be used when the Recordset object was opened with the CommandTypeEnum value of adCmdTableDirect.
注意:只有当Recordset对象以adCmdTableDirect中的CommandTypeEnum值打开时,才能使用这个方法。


--  作者:独行
--  发布时间:2013/3/20 12:15:59
--  
谢谢王峰!
那些资料我都试过的。一直没有实现。adUseServer,CursorLocation,Support(Index),Support(Seek)都测试和设置的,这几项没有问题。但还是一直通不过。
唯一不能确定的是,CommandTypeEnum我使用的方法对不对。我是用的Rs.Open cnn,SelectStr,1,3,512的方式,不知道这种方式对不对。

--  作者:王锋
--  发布时间:2013/3/20 13:28:56
--  

试试将数据库表字段上加上索引和主键后看看。

ADO的开发都是一样的,你也考虑先在ACCESS上进行开发,等通过后再把代码移植到金字塔


--  作者:独行
--  发布时间:2013/3/20 15:42:30
--  
不指定索引的话,默认是使用主键。要Seek的字段就是主键。
实在是没招了

--  作者:王锋
--  发布时间:2013/3/20 15:45:45
--  
金字塔所用的VBA实际上是VBS引擎,开发ADO数据的代码完全一致,你也考虑在其他的有关数据的编程论坛递交一下这个问题。