我用VB连接ACCESS数据库,通过一个SQL语句把一组符合要求的数据读入RECORDSET,然后我在RECORDSET里面怎么查询我要的一个字段ID等于'01'的数据,好象是用find的方法,不太会用,有没有其他方法让我在一个RECORDSET里面寻找符合我要求的字段,谢谢

解决方案 »

  1.   

    Find 方法 (ADO)
             搜索 Recordset 中满足指定条件的记录。如果条件符合,则记录集位置设置在找到的记录上,否则位置将设置在记录集的末尾。语法Find (criteria, SkipRows, searchDirection, start)参数criteria   字符串,包含用于搜索的指定列名、比较操作符和值的语句。SkipRows    可选,长整型值,其默认值为零。它指定当前行或 start 书签的位移以开始搜索。searchDirection    可选的 SearchDirectionEnum 值,指定搜索应从当前行还是搜索方向上的下一个有效行开始。其值可为 adSearchForward 或 adSearchBackward。搜索停止在记录集的开始还是末尾则取决于 searchDirection 值。start    可选,变体型书签,用作搜索的开始位置。说明criteria 中的“比较操作符”可以是“>”(大于)、“<”(小于)、“=”(等于)或“like”(模式匹配)。  criteria 中的值可以是字符串、浮点数或者日期。字符串值以单引号分隔(如“state = 'WA'”)。日期值以“#”(数字记号)分隔(如“start_date > #7/22/97#”)。如“比较操作符”为“like”,则字符串“值”可以包含“*”(某字符可出现一次或多次)或者“_”(某字符只出现一次)。(如“state like M_*”与 Maine 和 Massachusetts 匹配。)
      

  2.   

    楼上讲了理论,下面是例子-------下面的一个例子示范了如何用 ADO Find 方法查询记录: Sub FindRecord(strDBPath As String, _ strTable As String, _ strCriteria As String, _ strDisplayField As String) ' This procedure finds a record in the specified table by ' using the specified criteria. ' For example, to use this procedure to find records ' in the Customers table in the Northwind database ' that have " USA " in the Country field, you can ' use a line of code like this: ' FindRecord _ ' "c:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", _ ' "Customers", "Country=' USA '", "CustomerID" Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset ' Open the Connection object. Set cnn = New ADODB.Connection With cnn .Provider = "Microsoft.Jet.OLEDB.4.0" .Open strDBPath End With Set rst = New ADODB.Recordset With rst ' Open the table by using a scrolling ' Recordset object. .Open Source:=strTable, _ ActiveConnection:=cnn, _ CursorType:=adOpenKeyset, _ LockType:=adLockOptimistic ' Find the first record that meets the criteria. .Find Criteria:=strCriteria, SearchDirection:=adSearchForward ' Make sure record was found (not at end of file). If Not .EOF Then ' Print the first record and all remaining ' records that meet the criteria. Do While Not .EOF Debug.Print .Fields(strDisplayField).Value ' Skip the current record and find next match. .Find Criteria:=strCriteria, SkipRecords:=1 Loop Else MsgBox "Record not found" End If ' Close the Recordset object. .Close End With ' Close connection and destroy object variables. cnn.Close Set rst = Nothing Set cnn = Nothing End Sub------------
    www.vicmiao.com
    努力就有美好时光!
      

  3.   

    Find方法很少使用
    一个都是直接用Select语句筛选
      

  4.   

    理论和方法,楼上的都讲了,我该讲点啥好呢?
    Find方法,当进行某一段存盘工作之后,需要把此前存盘中的内容Show出来时,因为肯定要从数据库中Select记录,此时,用Find方法,就很方便的!Rec_Query.Requery
    Rec_Query.Find "字段=" & Trim(查询内容) & "
      

  5.   

    find 傻啊,只能用一个条件,还是filter吧,刚在用find加了一堆条件,直接傻了我用的do..loop进行记录集处理,死循环啊,条件都对阿,怎么还死循环了呢? 原来find 傻啊,只能用一个条件,楼主注意哦. rs.find "fieldname 运算符号 条件".我也是第一次用啊.嘻嘻~~ 楼主给点分哦.
      

  6.   

    用select... where查询啊,比较灵活的。