MaxRecords 属性范例

该范例使用 MaxRecords 属性打开包含标题表中 10 个最有价值标题的 Recordset

Public Sub MaxRecordsX()   Dim rstTemp As ADODB.Recordset
   Dim strCnn As String   ' 打开包含标题表中 10 个最有价值标题的记录集。
   strCnn = "Provider=sqloledb;" & _
      "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
   Set rstTemp = New ADODB.Recordset
   rstTemp.MaxRecords = 10
   rstTemp.Open "SELECT Title, Price FROM Titles " & _
      "ORDER BY Price DESC", strCnn, , , adCmdText   ' 显示记录集内容。
   Debug.Print "Top Ten Titles by Price:"   Do While Not rstTemp.EOF
      Debug.Print "  " & rstTemp!Title & " - " & rstTemp!Price
      rstTemp.MoveNext
   Loop
   rstTemp.CloseEnd Sub
www.2mysite.net