Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549

    ASP: come fare una funzione che ritorna un Recordset ?

    ciao, vorrei fare una funzione (a cui passo la stringa SQL) in cui in essa apro la connessione al database, apro il recordset e vorrei che mi tornasse l'intero recordset

    e' possibile ?

    per esempio una cosa del tipo :
    codice:
    function esegui(strSQL_arrivata)
    
    Set conn = Server.CreateObject("ADODB.Connection")		
    conn.ConnectionTimeout = Application("ALLOT_ConnectionTimeout")
    conn.CursorLocation = Application("ALLOT_CursorLocation") 
    conn.CommandTimeout = Application("ALLOT_CommandTimeout")
    conn.Open Application("ALLOT_ConnectionString"), Application("ALLOT_RuntimeUserName"), Application("ALLOT_RuntimePassword")
    
    Set RSxxx = Server.CreateObject("ADODB.Recordset")
    RSxxx.CursorType = adOpenDynamic
    RSxxx.LockType = 3
    
    esegui = RSxxx.open strSQL_arrivata, conn
    
    RSxxx.close
    Set RSxxx = Nothing
    conn.close
    Set conn = Nothing
    
    end function
    
    
    str = "select categoria from categorie where id_cat = 1 "
    
    Set RSlocale = Server.CreateObject("ADODB.Recordset")
    RSlocale.CursorType = adOpenDynamic
    RSlocale.LockType = 3
    
    RSlocale = esegui(str)
    
    if not RSlocale.eof then
    
    ....
    
    end if
    RSlocale.close
    Set RSlocale = Nothing
    pero' qui mi da' errore alla riga dove c'e' :

    codice:
    esegui = RSxxx.open strSQL_arrivata, conn
    
    Expected end of statement 
    /111.asp, line 26 
    esegui = RSxxx.open strSQL_arrivata, conn
    --------------------^
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Potresti usare la GetRows() che ti ritorna un array bidimensionale righe / colonne.

    Roby

  3. #3
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549
    Originariamente inviato da Roby_72
    Potresti usare la GetRows() che ti ritorna un array bidimensionale righe / colonne.

    Roby
    come la faresti tu nel codice ?

    codice:
    function esegui(strSQL_arrivata)
    
    Set conn = Server.CreateObject("ADODB.Connection")		
    conn.ConnectionTimeout = Application("ALLOT_ConnectionTimeout")
    conn.CursorLocation = Application("ALLOT_CursorLocation") 
    conn.CommandTimeout = Application("ALLOT_CommandTimeout")
    conn.Open Application("ALLOT_ConnectionString"), Application("ALLOT_RuntimeUserName"), Application("ALLOT_RuntimePassword")
    
    Set RSxxx = Server.CreateObject("ADODB.Recordset")
    RSxxx.CursorType = adOpenDynamic
    RSxxx.LockType = 3
    
    esegui = RSxxx.open (strSQL_arrivata, conn)
    
    RSxxx.close
    Set RSxxx = Nothing
    conn.close
    Set conn = Nothing
    
    end function
    
    
    str = "select categoria from categorie where id_cat = 1 "
    
    Set RSlocale = Server.CreateObject("ADODB.Recordset")
    RSlocale.CursorType = adOpenDynamic
    RSlocale.LockType = 3
    
    RSlocale = esegui(str)
    
    if not RSlocale.eof then
    
    ....
    
    end if
    RSlocale.close
    Set RSlocale = Nothing
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    set rs = conn.Execute(sql)
    if not rs.EOF then
    esegui = rs.GetRows()
    else
    esegui = null
    end if
    set rs = nothing
    La devi adattare.

    Roby

  5. #5
    Utente di HTML.it L'avatar di billy1
    Registrato dal
    Jun 2001
    Messaggi
    549

    grazie

    Originariamente inviato da Roby_72
    codice:
    set rs = conn.Execute(sql)
    if not rs.EOF then
    esegui = rs.GetRows()
    else
    esegui = null
    end if
    set rs = nothing
    La devi adattare.

    Roby
    grazie davvero, ottimo lavoro, veramente gentile.

    Posto qui il tutto che funziona :

    codice:
    function esegui(strSQL_arrivata)
    
    Set conn = Server.CreateObject("ADODB.Connection")		
    conn.ConnectionTimeout = Application("ALLOT_ConnectionTimeout")
    conn.CursorLocation = Application("ALLOT_CursorLocation") 
    conn.CommandTimeout = Application("ALLOT_CommandTimeout")
    conn.Open Application("ALLOT_ConnectionString"), Application("ALLOT_RuntimeUserName"), Application("ALLOT_RuntimePassword")
    
    set rs = conn.Execute(strSQL_arrivata)
    if not rs.EOF then
    esegui = rs.GetRows()
    else
    esegui = null
    end if
    set rs = nothing
    
    conn.close
    Set conn = Nothing
    
    end function
    
    
    str = "select categoria from categorie where id_cat = 1 "
    
    arr = esegui(str)
    Response.Write "
    lunghezza : "& ubound(arr)
    Response.Write "
    "& arr(0,0)
    Il fumo fa male a te e agli altri.
    Rispettate chi non vuole respirare il fumo passivo.

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.