#477 - Importare un array generato da GetRows in un recordset di ADO

L'oggetto recordset di ADO, attraverso il metodo GetRows, permette di esportare un recordset in un array.
E' molto utile per estrarre velocemente dati da un database e salvarli, ad esempio, in una variabile di Sessione.
Ma coma fare l'operazioni inversa, ovvero importare un Array generato attraverso GetRows in un Recordset?
Basterà sostituire nell'esempio che segue il codice che dichiara e valorizza l'array con quello necessario a recuperare lo stesso:

<%

Dim arrRs(2, 8)
arrRs(0, 0) = "1"
arrRs(1, 0) = "Gestire un cookie con più valori"
arrRs(0, 1) = "2"
arrRs(1, 1) = "Verificare che un file esista sul server"
arrRs(0, 2) = "3"
arrRs(1, 2) = "Spostare un file"
arrRs(0, 3) = "4"
arrRs(1, 3) = "Cancellare un file"
arrRs(0, 4) = "5"
arrRs(1, 4) = "Creare un array al volo"
arrRs(0, 5) = "6"
arrRs(1, 5) = "Come faccio a prendere tutto quello c'è dopo il ? in una richiesta?"
arrRs(0, 6) = "7"
arrRs(1, 6) = "Come si ordina una query SQL?"
arrRs(0, 7) = "8"
arrRs(1, 7) = "Ricavare un numero di utente univoco"

Set custRs = Server.CreateObject("ADODB.Recordset")

' creazione delle colonne
for x = 0 to ubound(arrRs, 1) - 1
  custRs.Fields.Append x, 200, 250
next

custRs.Open

' per ogni record
for i = 0 to ubound(arrRs, 2) - 1

  custRs.AddNew

  ' per ogni campo
  for x = 0 to ubound(arrRs, 1) - 1
    custRs(x) = arrRs(x, i)
  next

  custRs.Update

next

' Ordino in base al campo ID
custRs.Sort = "[0] DESC"

' Mostro il recordset appena ordinato
do until custRs.eof

    Response.Write "<li>" & custRs(0)
    Response.Write " - " & custRs(1)
    custRs.movenext

loop

custRs.Close
set custRs = Nothing

%>

Per maggiori informazioni si veda:

#37 - Registrare in una matrice il contenuto di una tabella di un database
http://www.aspitalia.com/liste/usag/script.aspx?ID=37

#222 - I disconnected recordset di ADO 2.x
http://www.aspitalia.com/liste/usag/script.aspx?ID=222


Approfondimenti

Commenti

Esprimi il tuo giudizio su questo script:

Per procedere devi essere autenticato.

Aggiungi un nuovo commento »»»
Per inserire un commento, devi registrarti alla nostra community.




IN EVIDENZA
MISC