国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Access > 正文

如何在Recordset對象中查詢記錄

2024-09-07 19:03:53
字體:
來源:轉載
供稿:網友

無論是 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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 胶南市| 荔浦县| 景谷| 安溪县| 南和县| 凤翔县| 马尔康县| 铜梁县| 田东县| 洪雅县| 旺苍县| 会昌县| 油尖旺区| 石嘴山市| 射洪县| 荥阳市| 丹阳市| 娄烦县| 太湖县| 阳高县| 马山县| 浦城县| 禹州市| 柳河县| 宝坻区| 满洲里市| 邢台县| 龙海市| 来安县| 巨野县| 古浪县| 宁蒗| 扎兰屯市| 新巴尔虎左旗| 洛隆县| 什邡市| 繁昌县| 丰台区| 泰安市| 张家口市| 江川县|