请问adodc的recodeset.find怎样用?

pasu 2000-07-28 03:27:00
请问adodc的recodeset.find怎样用?最好有例子,我的msdn里找不到.
...全文
102 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzh 2000-07-28
  • 打赏
  • 举报
回复
Find是用来进行记录查找的,也可以用Open来查找,在OPEN之前把SQL语句写好就可以了。
Tyro 2000-07-28
  • 打赏
  • 举报
回复
摘自msdn
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 匹配。)
  • 打赏
  • 举报
回复
This example uses the Recordset object's Find method to locate and count the number of business titles in the pubs database. The example assumes the underlying provider does not support similar functionality.

Public Sub Main()
FindX
End Sub

Public Sub FindX()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim mark As Variant
Dim count As Integer

count = 0
cnn.Open "DSN=pubs; Provider=MSDASQL; uid=sa; pwd=;"
rst.Open "SELECT title_id FROM titles", cnn, _
adOpenStatic, adLockReadOnly, adCmdText

' The default parameters are sufficient to search forward
' through a Recordset.

rst.Find "title_id LIKE 'BU%'"

' Skip the current record to avoid finding the same row repeatedly.
' The bookmark is redundant because Find searches from the current
' position.

Do While rst.EOF <> True 'Continue if last find succeeded.
Debug.Print "Title ID: "; rst!title_id
count = count + 1 'Count the last title found.
mark = rst.Bookmark 'Note current position.
rst.Find "title_id LIKE 'BU%'", 1, adSearchForward, mark
Loop

rst.Close
cnn.Close
Debug.Print "The number of business titles is " & count

End Sub

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧