AbsolutePosition 和 CursorLocation 属性范例

该范例说明 AbsolutePosition 属性如何对枚举所有 Recordset 记录的循环进程进行跟踪。它通过将游标设置为客户端游标,使用 CursorLocation 属性激活 AbsolutePosition 属性。

Public Sub AbsolutePositionX()   Dim rstEmployees As ADODB.Recordset
   Dim strCnn As String
   Dim strMessage As String   ' 使用客户端游标为雇员表打开一个记录集。
   strCnn = "Provider=sqloledb;" & _
      "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
   Set rstEmployees = New ADODB.Recordset
   ' 使用客户端游标激活 AbsolutePosition 属性。
   rstEmployees.CursorLocation = adUseClient
   rstEmployees.Open "employee", strCnn, , , adCmdTable
   
   ' 枚举记录集。
   Do While Not rstEmployees.EOF
      ' 显示当前记录信息。
      strMessage = "Employee: " & rstEmployees!lName & vbCr & _
         "(record " & rstEmployees.AbsolutePosition & _
         " of " & rstEmployees.RecordCount & ")"
      If MsgBox(strMessage, vbOKCancel) = vbCancel _
         Then Exit Do
      rstEmployees.MoveNext
   Loop   rstEmployees.CloseEnd Sub
www.51windows.Net