?
Solved

Setting RowCount

Posted on 1998-08-05
6
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 160 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 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