Solved

Setting RowCount

Posted on 1998-08-05
6
410 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

914 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

12 Experts available now in Live!

Get 1:1 Help Now