在Recordset对象中查询记录的方法
来源:ddvip.com 发布时间:2008-11-20 16:51:00
无论是 DAO 还是 ADO 都有两种从 Recordset 对象中查询记录的方法: Find 方法和 Seek 方法。在这两种方法中可以让你指定条件进行查询与其相应的记录 , 一般而言,在相同条件下, Seek 方法提供了比 Find 方法更好的性能,因为 Seek 方法是基于索引的。因为这个原因基本提供者必须支持 Recordset 对象上的索引,可以用 Supports ( adSeek ) 方法确定基本提供者是否支持 Seek ,用 Supports ( adIndex ) 方法确定提供者是否支持索引。(例如, OLE DB Provider for Microsoft Jet 支持 Seek 和 Index 。),请将 Seek 方法和 Index 属性结合使用。如果 Seek 没有找到所需的行,将不会产生错误,该行将被放在 Recordset 的结尾处。执行此方法前,请先将 Index 属性设置为所需的索引。此方法只受服务器端游标支持。如果 Recordset 对象的 CursorLocation 属性值为 adUseClient ,将不支持 Seek 。只有当 CommandTypeEnum 值为 adCmdTableDirect 时打开 Recordset 对象,才可以使用此方法。
用 ADO Find 方法
DAO 包含了四个“ Find ”方法: FindFirst,FindLast,FindNext 和 FindPrevious .
DAO 方法 ADO Find 方法
下面的一个例子示范了如何用 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 FilesMicrosoft OfficeOfficeSamplesNorthwind.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


猜你喜欢
- 本文实例讲述了Flask教程之重定向与错误处理。分享给大家供大家参考,具体如下:Flask类有一个redirect()方法. 当我们调用它时
- $array=explode(separator,$string); $string=implode(glue,$array);使用和理解这
- 写在前面数据库本质上是一种共享资源,因此在最大程度提供并发访问性能的同时,仍需要确保每个用户能以一致的方式读取和修改数据。锁机制(Locki
- 也有些正则方法可以限制回归算法输出结果中系数的影响,其中最常用的两种正则方法是lasso回归和岭回归。lasso回归和岭回归算法跟常规线性回
- 本文学习如何在Golang程序中执行Shell命令(如,ls,mkdir或grep),如何通过stdin和stdout传入I/O给正在运行的
- 本文中介绍的系统优化,主要针对前端和后台这两方面(后台方面主要对SQL语句和数据存储进行了优化),下文中我们将介绍一些优化技巧和经验。技巧:
- python的pyaudio可以进行录音,播放,生成wav文件等等,WAVE是录音时用的标准的WINDOWS文件格式,文件的扩展名为WAV,
- 1,检查默认安装的mysql的字符集mysql> show variables like '%char%';+----
- 在ASP编程中,身份认证可以说是常要用到的。但怎么样才能做到认证的安全呢?表单提交页面:sub.htm &
- __getattr__函数的作用: 如果属性查找(attribute lookup)在实例以及对应的类中(通过__dict__)失败, 那么
- 简而言之就是,nn.Sequential类似于Keras中的贯序模型,它是Module的子类,在构建数个网络层之后会自动调用forward(
- 以下的文章主要是介绍MySQL5创建存储过程的实例演示,MySQL5创建存储在实际操作中应用的频率还是很高的,以下就是MySQL5创建存储过
- JavaScript在讲解用 Ts 遍历一个对象之前, 我们先说说 在 Js 中怎么实现, for...in、Object.keys, 一个
- 简介testing是 Go 语言标准库自带的测试库。在 Go 语言中编写测试很简单,只需要遵循 Go 测试的几个约定,与编写正常的 Go 代
- 现在大家学习python掌握内容了解太多太多,但是最重要的不是掌握了解算法的使用,而是了解算法原理远比使用算法命令更重要,现在大家了解算法应
- 前言回调函数是我们在python编程中经常会遇到的一个问题,而想在将来某一时刻进行函数回调,可以使用call_later()函数来实现,第一
- <P><HTML><HEAD><TITLE>javascriptboy</TITLE&
- 本文实例讲述了PHP动态生成指定大小随机图片的方法。分享给大家供大家参考,具体如下:<?php$image_width = 100;$
- mysql 创建的优化就是加索引,可是有时候会遇到加索引都没法达到想要的效果的情况,加上了所以,却还是搜索的全数据,原因是sqlEXPLAI
- 前言在SQL Server中,我们知道一个SELECT语句执行过程中只会申请一些意向共享锁(IS) 与共享锁(S), 例如我使用SQL Pr