MaxRecords プロパティの例 (VB)

次の例では、MaxRecords プロパティを使って、Titles テーブル中の最も高価な 10 タイトルを含む Recordset を開きます。

Public Sub MaxRecordsX()

    Dim rstTemp As ADODB.Recordset
    Dim strCnn As String

    ' Open recordset containing the 10 most expensive
    ' titles in the Titles table.
    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

    ' Display the contents of the recordset.
    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