Il giorno Tue, 19 Aug 2008 09:37:13 -0700, =?Utf-8?B?UmljaA==?=
<Rich@xxxxxx> ha scritto:
Quote:
>Anyway, now I need to do something similar in an HTA file. How do I display
>the data in a table format like the asp?
This displays the rows of a table from an mdb dropped on the icon.
It asks the name of a table contained in the db.
I have another vbs who shows all the tables of the mdb file.
' *****************************************************
' ADO elenco righe di una tabella.vbs
' (c) Cenati Giovanni -
http://digilander.libero.it/Cenati
' Codice vbs liberamente utilizzabile citando il sito
' Trascinare un file mdb sull'icona dello script.
' Viene chiesto il nome di una tabella dell'archivio.
' Mostra in una finestra di Internet Explorer tutte o una
' parte delle righe della tabella.
' Drop an MDB file on the icon. The script asks
' the name of a valid table of the database.
' Then shows an Internet Explorer window with a list of
' all or part of the records found in the table.
' *****************************************************
Title= "Elenco contenuto di un database - by Cenati Giovanni"
Set objArgs = WScript.Arguments 'Vedo se c'è un agrogmento passato allo script
if objargs.count<>1 then 'altrimenti mostro come si usa il programma
msgbox "Trascinare un file mdb sul programma.",vbInformation+vbOkonly,Title
wscript.quit
end if
DbFile = objArgs(0) 'questa variabile contiene il nome del file da leggere
Set oRecordset = createobject("ADODB.Recordset")
Set oConnection = createobject("ADODB.Connection")
oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbFile & ";"
oRecordset.ActiveConnection = oConnection
oRecordset.CursorType=1 : oRecordset.LockType=3
TableName = inputbox( "Nome della tabella?" ,title )
' SQL = "SELECT * FROM Products Where SupplierID=2"
SQL = "SELECT * FROM " & TableName
' Crea un recordset con tutte le colonne dalla tabella che vogliamo.
oRecordset.Open SQL, oConnection
'Gestisco l'errore se il recordset è vuoto.
If oRecordset Is Nothing Then msgbox "Nessun record.",,Title:wscript.quit
'Trovo il numero totale di record che ho estratto.
nRecord= oRecordset.Recordcount
'E chiedo se li si vuole mostrare tutti.
nRecordDaMostrare=int(inputbox("Quanti record mostro?",Title,nRecord))
if nRecordDaMostrare>nRecord then nRecordDaMostrare=nRecord
if nRecordDaMostrare=0 then wscript.quit
'*** Crea una finestra che funge da output ***
Set myIE = CreateObject("InternetExplorer.Application")
myIE.Navigate "about
:blank"
myIE.ToolBar = True:myIE.StatusBar = False:myIE.Resizable = True
Do:wscript.sleep 100:Loop While myIE.Busy
myIE.Width = 600:myIE.Height = 400
myIE.Left = 50:myIE.Top = 50
myIE.Visible = True
myIE.document.writeln("<html><title></title>"&_
"<body><DIV id='cont'></DIV></body></html>")
Set IEWindow = myIE.Document.all("cont")
'**********************************************
' Elenco alcuni dati sul database e sui record.
lista= "<h2>Database: " & DbFile & "<h2><br>" 'Nome del database
lista= lista & "<h4>" 'il resto lo scrivo più piccolo.
lista=lista & "Numero record totali: " & nRecord & "<br>"
lista=lista & "Numero record mostrati: " & nRecordDaMostrare & "<br>"
lista= lista & "Elenco record della tabella " & TableName & ":<br><br>"
lista= lista & "<table BORDER=1 CELLPADDING=2 CELLSPACING=2 >"
lista= lista & "<tr>" 'Inizia la riga con i nomi dei campi
' Sono oRecordset.fields.count, numerati partendo da zero.
For i=0 To oRecordset.fields.count-1
lista= lista & "<td>" & oRecordset.fields(i).name & "</td>"
Next
lista= lista & "<td># Record</td></tr>" 'termina la riga con le intestazioni.
' Mi sposto alla prima riga selezionata
oRecordset.MoveFirst
' Leggo i record e li impagino in una tabella html.
Do
lista=lista & "<tr>" 'Inizio una riga (un record)
For i=0 To oRecordset.fields.count-1
'per il record corrente chiedo il contenuto del campo i-esimo
lista = lista & "<td>" & oRecordset.fields(i) & "</td>"
'Posso anche chiedere un campo specifico
'con, ad esempio, oRecordset.fields("ProductName")
Next
'lista=lista & "</tr>" 'Fine riga con un record
'oppure aggiunge anche il numero progressivo del record.
lista=lista & "<td>" & orecordset.absoluteposition & "</td></tr>"
oRecordset.movenext
'e passo al record successivo (se non sono già alla fine).
Loop until oRecordset.eof Or (oRecordset.AbsolutePosition = nRecordDaMostrare + 1)
lista=lista & "</table><br>" 'Termino la tabella
IEWindow.innerhtml = lista
oConnection.close
Set oConnection = Nothing
Set oRecordset = Nothing
'********* ADO elenco righe di una tabella.vbs ***************
--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--