Solved

Setting RowCount

Posted on 1998-08-05
6
407 Views
Last Modified: 2010-05-03
Is there a way to limit the amount of records that are returned by a recordset? Can i set the rowcount in the query and then the RS will only return that amount of records.
0
Comment
Question by:Coates
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1467926
Here is a sample :

SELECT TOP 25
FirstName, LastName
FROM Students
WHERE GraduationYear = 1997
ORDER BY GradePointAverage DESC;
0
 

Author Comment

by:Coates
ID: 1467927
What does the DESC mean?
0
 
LVL 14

Expert Comment

by:waty
ID: 1467928
It means that all the record will be sorted descently.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Coates
ID: 1467929
Ive tried this using telnet to my sybase server, and i get a syntax error near '25'. I dont think my version of sybase supports that method.
0
 

Author Comment

by:Coates
ID: 1467930
Ive tried this using telnet to my sybase server, and i get a syntax error near '25'. I dont think my version of sybase supports that method.
0
 
LVL 1

Accepted Solution

by:
BlackAndWhite earned 40 total points
ID: 1467931
It depends on what you are using

1. If you are using rdo with an rdoQuery
---------------------------------------------------
    Dim env As rdoEnvironment
    Dim db As rdoConnection
    Dim qd As rdoQuery
    Dim rs As rdoResultset
   
    Set env = rdoEnvironments(0)
    Set db = env.OpenConnection(dsName:="MYDSN", Connect:=".......")
    Set qd = db.CreateQuery(Name:="tmp", sqlString:="Select * from Products")
    qd.MaxRows = 10
    Set rs = qd.OpenResultset(rdOpenStatic)
   
    'Now rs should have been restricted to 10 recs.,.

2. If you are using DAO here is a sample from the help using CacheSize
---------------------------------------------------

Sub ClientServerX3()

      Dim dbsCurrent As Database
      Dim tdfRoyalties As TableDef
      Dim rstRemote As Recordset
      Dim sngStart As Single
      Dim sngEnd As Single
      Dim sngNoCache As Single
      Dim sngCache As Single
      Dim intLoop As Integer
      Dim strTemp As String
      Dim intRecords As Integer

      ' Open a database to which a linked table can be
      ' appended.
      Set dbsCurrent = OpenDatabase("DB1.mdb")

      ' Create a linked table that connects to a Microsoft SQL
      ' Server database.

Set tdfRoyalties = _
            dbsCurrent.CreateTableDef("Royalties")
      tdfRoyalties.Connect = _
            "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers"
      tdfRoyalties.SourceTableName = "roysched"
      dbsCurrent.TableDefs.Append tdfRoyalties
      Set rstRemote = _
            dbsCurrent.OpenRecordset("Royalties")

      With rstRemote
            ' Enumerate the Recordset object twice and record
            ' the elapsed time.
            sngStart = Timer

            For intLoop = 1 To 2
                  .MoveFirst

Do While Not .EOF
                        ' Execute a simple operation for the
                        ' performance test.
                        strTemp = !title_id
                        .MoveNext
                  Loop
            Next intLoop

            sngEnd = Timer
            sngNoCache = sngEnd - sngStart

            ' Cache the first 50 records.
            .MoveFirst
            .CacheSize = 50
            .FillCache
            sngStart = Timer

            ' Enumerate the Recordset object twice and record
            ' the elapsed time.
            For intLoop = 1 To 2
                  intRecords = 0

MoveFirst
                  Do While Not .EOF
                        ' Execute a simple operation for the
                        ' performance test.
                        strTemp = !title_id
                        ' Count the records. If the end of the
                        ' cache is reached, reset the cache to the
                        ' next 50 records.
                        intRecords = intRecords + 1
                        .MoveNext
                        If intRecords Mod 50 = 0 Then
                              .CacheStart = .Bookmark
                              .FillCache
                        End If
                  Loop
            Next intLoop

sngEnd = Timer
            sngCache = sngEnd - sngStart

            ' Display performance results.
            MsgBox "Caching Performance Results:" & vbCr & _
                  "    No cache: " & Format(sngNoCache, _
                  "##0.000") & " seconds" & vbCr & _
                  "    50-record cache: " & Format(sngCache, _
                  "##0.000") & " seconds"
            .Close
      End With

      ' Delete linked table because this is a demonstration.
      dbsCurrent.TableDefs.Delete tdfRoyalties.Name
      dbsCurrent.Close

End Sub

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now