Visualizzazione dei risultati da 1 a 7 su 7

Discussione: errore di paginazione

  1. #1

    errore di paginazione

    codice:
    <%@LANGUAGE = VBScript%>
    <%
        Dim sc, cn, rs, quanti, pag, contatore
    
        sc = ""
        sc = sc & "driver={Microsoft Access Driver (*.mdb)};dbq="
        sc = sc & Server.MapPath("database.mdb")
    
        Set cn = Server.CreateObject("ADODB.Connection")
        Set rs = Server.CreateObject("ADODB.Recordset")
    
       cn.Open sc
    
        quanti = 5
    
        pag = Request.QueryString("pag")
        If IsNumeric(pag) = False Or pag < 1 Then pag = 1
    
        contatore = 0
    %>
    <html>
    <head>
    <title>Paginazione dei risultati di query molto lunghe in ASP</title>
    <style>a { color: blue; }</style>
    </head>
    <body>
    
    <table align="center" width="300" border="1">
    <%
        rs.Open "SELECT nome FROM utenti ORDER BY nome ASC", cn, 1
        rs.PageSize = quanti
        rs.AbsolutePage = pag   
       While rs.EOF = False And contatore < quanti
    %>
        <tr><td><%=rs("nome")%></td></tr>
    <%
            rs.MoveNext
            contatore = contatore + 1
        Wend
    %>
    </table>
    
    </body>
    </html>
    <%
        rs.Close
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
    %>
    <p align="center">
    <%If pag > 1 Then%>
        Indietro
    <%End If%>
    <%
        Dim x
        x = 1
        For x = 1 To rs.PageCount
            If CInt(pag) <> x Then
    %>
                [<%=x%>]
    <%
            Else
    %>
                [<%=x%>]
    <%
            End If
        Next
    %>
    <%If rs.EOF = False Then%>
        Avanti
    <%End If%>
    </p>
    Nel momento in cui non trova nessun record mi da errore nella pagina sulla riga in rosso...

    è possibile ovviare alla cosa?

  2. #2
    Metti questi controlli
    codice:
    pag = Request.QueryString("pag")
    if len(pag) = 0 or (not isNumeric(pag)) then pag = 1
    if pag < 1 then pag = 1

  3. #3
    sia così

    codice:
     <%
        rsP.CursorLocation = 3
    	
        if Request.Querystring("sottocat") <> "" then	
    	rsP.Open "SELECT * FROM catalogo WHERE (categoria = '"&request.querystring("categoria")&"') AND (sottocat = '"&request.querystring("sottocat")&"') AND (online ='si') ORDER BY  sottocat DESC", conn, 1
    	else
    	rsP.Open "SELECT * FROM catalogo WHERE (categoria = '"&request.querystring("categoria")&"') AND (online ='si') ORDER BY  sottocat DESC", conn, 1
    	end if
    	
        rsP.PageSize = quanti
    	
    	pag = Request.QueryString("pag")
    	if len(pag) = 0 or (not isNumeric(pag)) then pag = 1
    	if pag < 1 then pag = 1
    	rsP.AbsolutePage = pag 
        Response.Write("<table border='0' cellpadding='0' cellspacing='0'><tr>")
     
    
        While rsP.EOF = False And contatore < quanti
    %>
    che così

    codice:
     <%
        rsP.CursorLocation = 3
    	
        if Request.Querystring("sottocat") <> "" then	
    	rsP.Open "SELECT * FROM catalogo WHERE (categoria = '"&request.querystring("categoria")&"') AND (sottocat = '"&request.querystring("sottocat")&"') AND (online ='si') ORDER BY  sottocat DESC", conn, 1
    	else
    	rsP.Open "SELECT * FROM catalogo WHERE (categoria = '"&request.querystring("categoria")&"') AND (online ='si') ORDER BY  sottocat DESC", conn, 1
    	end if
    	
        rsP.PageSize = quanti
    	rsP.AbsolutePage = pag 
    	pag = Request.QueryString("pag")
    	if len(pag) = 0 or (not isNumeric(pag)) then pag = 1
    	if pag < 1 then pag = 1
    	
        Response.Write("<table border='0' cellpadding='0' cellspacing='0'><tr>")
     
    
        While rsP.EOF = False And contatore < quanti
    %>
    ma da sempre errore

    codice:
    ADODB.Recordset error '800a0bcd' 
    
    Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. 
    
    /IT/paginazione.asp, line 24

  4. #4
    l'errore indica che il record cercato non c'è

    iserisci un if
    <%
    rs.Open "SELECT nome FROM utenti ORDER BY nome ASC", cn, 1
    rs.PageSize = quanti
    rs.AbsolutePage = pag
    if not rs.eof then
    While rs.EOF = False And contatore < quanti
    %>



    ovviamente alla fine del ciclo

    <%end if%>
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  5. #5
    Allora metti dopo l'esecuzione della query:
    codice:
    if not rsP.eof then
    
    rsP.PageSize = quanti
    	
    	pag = Request.QueryString("pag")
    	if len(pag) = 0 or (not isNumeric(pag)) then pag = 1
    	if pag < 1 then pag = 1
    	rsP.AbsolutePage = pag 
        Response.Write("<table border='0' cellpadding='0' cellspacing='0'><tr>")
     
    
        While rsP.EOF = False And contatore < quanti
    %>
    ...
    <%
    ...
    end if
    ...
    %>

  6. #6
    grazie ragazzi!!


  7. #7
    de nada
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.