1.    19 Aug 2008 #1
    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

  2.    19 Aug 2008 #2
    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:

    >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

  3.    19 Aug 2008 #3
    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

  4.    22 Aug 2008 #4
    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:

    >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


Similar Threads
Thread Forum
How to convert Table Data to CSV?
Hi guys. How can I convert the output of "net session" to csv or objects? PS C:\> net session Computer User name ...
PowerShell
Goofed up GPT partition table... Data Lost?
I have a 320 GB drive in a USB external converter (the big plastic shell that turns any IDE drive into a USB 2.0 drive). I did something I...
Vista General
Goofed up GPT partition table... Data Lost?
I have a 320 GB drive in a USB external converter (the big plastic shell that turns any IDE drive into a USB 2.0 drive). I did something I...
Vista file management
Goofed up GPT partition table... Data Lost?
I have a 320 GB drive in a USB external converter (the big plastic shell that turns any IDE drive into a USB 2.0 drive). I did something I...
Vista hardware & devices
Adding data to a hash table
I have imported a csv using import-csv $clcode = import-csv $csvlocation | select clcode $clcode results are a list of 6 digit numbers, for the...
PowerShell
Creating files from Data Table
i have an interesting need and one that i am almost there with but can't get the last bit. i am querying the database to get a results set. Within...
PowerShell
How do I get format-table to drop that omission points (...) and display my data
I am doing: PS C:\> ls C:\WINDOWS\system32\drivers\etc | ft LastWriteTime,FullName LastWriteTime FullName...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • PC Help Forum
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    © Designer Media Ltd
    All times are GMT -5. The time now is 23:35.
    .