Solved

Setting RowCount

Posted on 1998-08-05
6
412 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

829 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