Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista Tutorial - HTA file - display data from DB records in table like ASP - how?

Reply
 
Old 08-19-2008   #1 (permalink)
Rich
Guest


 
 

HTA file - display data from DB records in table like ASP - how?

In ASP I can display data from database records in a table using something
like
....
<td><%response.write(rs("FirstName")%></td>
<td><%response.write(rs("Lastname")%></td>
....
(I forget - I haven't written asp in a while)

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?

Thanks,
Rich

My System SpecsSystem Spec
Old 08-19-2008   #2 (permalink)
Reventlov
Guest


 
 

Re: HTA file - display data from DB records in table like ASP - how?

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)
--
My System SpecsSystem Spec
Old 08-19-2008   #3 (permalink)
Rich
Guest


 
 

Re: HTA file - display data from DB records in table like ASP - ho

Thanks. I figured out something a little bit simpler -- I use the innerHTML
property of the div tag.


<html>
<head>
<title>Test_A1</title>
<hta:application
id="lhta"
applicationname=test_A1.hta"
singleinstance="yes"
windowstate="normal"
caption="yes"
showintaskbar="yes"
sysmenu="yes"
scroll="No"
Icon="Icon5.ico"
/>

<script language="vbScript">

Sub CopyMemberDB()
Dim conn, str1
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Code\testAcc\db1test.mdb"
Set rsData = conn.Execute("SELECT * FROM Stuff")
str1 = "<table border=1>"
Do Until rsData.EOF = True
str1 = str1 & "<tr><td>" & rsData(1) & "</td><td>" & rsData(2) &
"</td><td>" & rsData(3) & "</td></tr>"
rsData.moveNext
Loop
str1 = str1 & "</table>"
myContent.innerHTML = str1
'myContent.innerHTML = "<table
border=1><tr><td>testing1</td><td>testing2</td></tr><tr><td>testing3</td><td>testing4</td></tr></table>"
End Sub
</script>
</head>
<div id="myContent"></div>
<body bgcolor=aqua>
<table border=0>
<tr>
<td><input type="submit" value= "Copy Member DB"
OnClick="CopyMemberDB()"></td>
</tr>
</table>

<h2>Test Buttons</h2>


</body>
</html>


My System SpecsSystem Spec
Old 08-22-2008   #4 (permalink)
Reventlov
Guest


 
 

Re: HTA file - display data from DB records in table like ASP - ho

Il giorno Tue, 19 Aug 2008 11:35:03 -0700, =?Utf-8?B?UmljaA==?=
<Rich@xxxxxx> ha scritto:
Quote:

>Thanks. I figured out something a little bit simpler -- I use the innerHTML
>property of the div tag.
Yes, I did the same in my script.
From the subject of the post I thought you were interested in how to get the data from db
records.
Giovanni.
--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Goofed up GPT partition table... Data Lost? Vista General
Goofed up GPT partition table... Data Lost? Vista hardware & devices
Adding data to a hash table PowerShell
Creating files from Data Table PowerShell
How do I get format-table to drop that omission points (...) and display my data PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46