如何在Recordset對(duì)象中查詢記錄_Access數(shù)據(jù)庫(kù)教程
推薦:解析Access中如何自動(dòng)建立表的連接表達(dá)式連接可以生成有意義的視圖或SQL虛擬集, 連接有: 內(nèi)連接(自然連接): 只有兩個(gè)表相匹配的行才能在結(jié)果集中出現(xiàn) 外連接:包括左外連接(左邊的表不加限制),右外連接(右邊的表不加限制)
無(wú)論是 DAO 還是 ADO 都有兩種從 Recordset 對(duì)象中查詢記錄的方法: Find 方法和 Seek 方法。在這兩種方法中可以讓你指定條件進(jìn)行查詢與其相應(yīng)的記錄 , 一般而言,在相同條件下, Seek 方法提供了比 Find 方法更好的性能,因?yàn)?Seek 方法是基于索引的。因?yàn)檫@個(gè)原因基本提供者必須支持 Recordset 對(duì)象上的索引,可以用 Supports ( adSeek ) 方法確定基本提供者是否支持 Seek ,用 Supports ( adIndex ) 方法確定提供者是否支持索引。(例如, OLE DB Provider for Microsoft Jet 支持 Seek 和 Index 。),請(qǐng)將 Seek 方法和 Index 屬性結(jié)合使用。如果 Seek 沒(méi)有找到所需的行,將不會(huì)產(chǎn)生錯(cuò)誤,該行將被放在 Recordset 的結(jié)尾處。執(zhí)行此方法前,請(qǐng)先將 Index 屬性設(shè)置為所需的索引。此方法只受服務(wù)器端游標(biāo)支持。如果 Recordset 對(duì)象的 CursorLocation 屬性值為 adUseClient ,將不支持 Seek 。只有當(dāng) CommandTypeEnum 值為 adCmdTableDirect 時(shí)打開(kāi) Recordset 對(duì)象,才可以使用此方法。
用 ADO Find 方法
DAO 包含了四個(gè)“ Find ”方法: FindFirst,FindLast,FindNext 和 FindPrevious .
DAO 方法 ADO Find 方法
下面的一個(gè)例子示范了如何用 ADO Find 方法查詢記錄:
| 以下為引用的內(nèi)容: 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 |
分享:解讀安全的ACCESS加密方法Microsoft的ACCESS數(shù)據(jù)庫(kù),是我們常用的桌面數(shù)據(jù)之一,大多中小企業(yè)的數(shù)據(jù)庫(kù)管理系統(tǒng)都可以采用它,但其安全性一直令人擔(dān)猶,試想,一套財(cái)務(wù)管理系統(tǒng),用戶直接打開(kāi)數(shù)據(jù)庫(kù)去更改數(shù)據(jù)
- Access數(shù)據(jù)庫(kù)安全策略之ASP式
- 第N次被ACCESS的關(guān)鍵字涮
- Access中用Jet SQL語(yǔ)句刪除表關(guān)系
- Access報(bào)表打印如何自動(dòng)分頁(yè)
- Access完成累計(jì)余額的計(jì)算
- 搭建Access為主的Mdb數(shù)據(jù)庫(kù)
- 一句sql更新兩個(gè)表并可更新對(duì)應(yīng)的字段值具體實(shí)現(xiàn)
- MySQL查詢優(yōu)化:連接查詢排序limit(join、order by、limit語(yǔ)句)介紹
- 內(nèi)網(wǎng)ssh/mysql登錄緩慢的解決方法
- 使用準(zhǔn)則進(jìn)行條件查詢--1.4.從窗體中選擇查詢的條件
- 中文Access2000速成教程--1.1 使用“向?qū)А痹O(shè)計(jì)數(shù)據(jù)庫(kù)
- 中文Access2000速成教程--1.3 在“設(shè)計(jì)”視圖中設(shè)計(jì)表
Access數(shù)據(jù)庫(kù)教程Rss訂閱編程教程搜索
Access數(shù)據(jù)庫(kù)教程推薦
猜你也喜歡看這些
- 怎樣用代碼隱藏、最大化、最小化ACCESS的主窗口
- 帶你深入了解Access數(shù)據(jù)庫(kù)的4種安全方式
- Access數(shù)據(jù)庫(kù)開(kāi)發(fā)技巧(四)
- Oracle與Access表之間的導(dǎo)入和導(dǎo)出實(shí)現(xiàn)
- C# 連接Access數(shù)據(jù)時(shí)總報(bào)找不到dbo.mdb的問(wèn)題
- 數(shù)據(jù)庫(kù)設(shè)計(jì)范式
- Access作為網(wǎng)站數(shù)據(jù)庫(kù)的弊端
- ASP完美轉(zhuǎn)化ACCESS為SQL數(shù)據(jù)庫(kù)連接
- 注意!Access不為人知的秘密技巧和陷阱。
- 解答Perl下如何連接Access數(shù)據(jù)庫(kù)
- 相關(guān)鏈接:
- 教程說(shuō)明:
Access數(shù)據(jù)庫(kù)教程-如何在Recordset對(duì)象中查詢記錄
。