VB中使用ADO能用seek方法吗?
对于access的数据库,本人用 rs.Supports(adIndex) 检查,结果为false,所以不知在什么条件下才能使用
http://download.csdn.net/detail/veron_04/1644211
'Seek 方法和 Index 属性范例 (VB)
'本范例使用 Recordset 对象的 Seek 方法、Index 属性和给定的 Employee ID,在 Nwind.mdb 数据库的 Employees 表中定位雇员名。
Public Sub Main()
SeekX
End Sub
Public Sub SeekX()
Dim rst As ADODB.Recordset
Dim strID As String
Dim strPrompt As String
strPrompt = "Enter an EmployeeID (e.g., 1 to 9)"
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open "employees", _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\temp\northwind.mdb;" & _
"user id=admin;password=;", _
adOpenKeyset, adLockReadOnly, adCmdTableDirect
' Does this provider support Seek and Index?
If rst.Supports(adIndex) And rst.Supports(adSeek) Then
rst.Index = "EmployeeId"
' Display all the employees.
rst.MoveFirst
Do While rst.EOF = False
Debug.Print rst!EmployeeID; ": "; rst!firstname; " "; _
rst!LastName
rst.MoveNext
Loop
' Prompt the user for an EmployeeID between 1 and 9.
rst.MoveFirst
Do
strID = LCase(Trim(InputBox(strPrompt, "Seek Example")))
' Quit if strID is a zero-length string (CANCEL, null, etc.)
If Len(strID) = 0 Then Exit Do
If Len(strID) = 1 And strID >= "1" And strID <= "9" Then
rst.Seek Array(strID), adSeekAfterEQ
If rst.EOF Then
Debug.Print "Employee not found."
Else
Debug.Print strID; ": Employee='"; rst!firstname; " "; _
rst!LastName; "'"
End If
End If
Loop
End If
rst.Close
End Sub
补充:VB , 数据库(包含打印,安装,报表)