limit recordset return

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    limit recordset return

    Hi, I have this code and it works fine. I want to only display 10 results out of my database of 1000. I have tried adding the limit 10; code but get a syntax error.
    Where CategoryID=" & 60 & " limit 10;"

    I tried adding rs.PageSize = 10, but that was no good either.

    <%
    'Create an ADO connection object
    Set adoCon = Server.CreateOb ject("ADODB.Con nection")
    ' Database connection
    Set con = CreateObject("A DODB.Connection ")
    con.Provider = "Microsoft.Jet. OLEDB.4.0"
    con.Open Server.MapPath( "database/greeting.mdb")
    'Create an ADO recordset object
    Set rs = Server.CreateOb ject("ADODB.Rec ordset")
    sql = "Select author,uk,cardd escription FROM tblGreetingPost Cards Where CategoryID=" & 60 & ""
    'Open the recordset with the SQL query
    rs.Open SQL, Con
    'Loop through the recordset
    Do While not rs.EOF
    'Write the HTML to display the current record in the recordset
    Response.Write " <b><ul><li><spa n><a class=""mena"" title=""" & rs("carddescrip tion") & """ href=""day.asp? uk=" & rs("uk") & """>" & rs("carddescrip tion") & "</a></span></li></ul></b>"
    rs.MoveNext
    Loop

    'Reset server objects
    rs.Close
    Set rs = Nothing
    Set Con = Nothing
    %>
    </li>


    Any help would be appreciated. I am sure its a small thing but cannot fathom it out.
    Thanks in advance
    Richard
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    I think this is dependent on the type of db, but I use "SET ROWCOUNT 10; " at the beginning of the query in SQL Server. Let me know if this helps.

    Jared

    Comment

    • Nicodemas
      Recognized Expert New Member
      • Nov 2007
      • 164

      #3
      It looks like you are using Microsoft Access.

      Revise your query to this in order to only pull 10 records:
      Code:
      SELECT TOP 10 author,uk,carddescription FROM tblGreetingPostCards Where CategoryID=60

      Comment

      • fran7
        New Member
        • Jul 2006
        • 229

        #4
        Thanks Nicodemas, worked a treat.
        Richard

        Comment

        Working...