此頁沒有內(nèi)容條目
內(nèi)容

MaxRecords 屬性范例

該范例使用 MaxRecords 屬性打開包含標(biāo)題表中 10 個最有價值標(biāo)題的 Recordset。

Public Sub MaxRecordsX()

   Dim rstTemp As ADODB.Recordset

   Dim strCnn As String

   ' 打開包含標(biāo)題表中 10 個最有價值標(biāo)題的記錄集。

   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

   ' 顯示記錄集內(nèi)容。

   Debug.Print "Top Ten Titles by Price:"

   Do While Not rstTemp.EOF

      Debug.Print "  " & rstTemp!Title & " - " & rstTemp!Price

      rstTemp.MoveNext

   Loop

   rstTemp.Close

End Sub