![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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 Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
|
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) | ||||||||||||
| 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:
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 Specs![]() | |||||||||||||
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) | ||||||||||||
| 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:
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 Specs![]() | |||||||||||||
|
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Goofed up GPT partition table... Data Lost? | __ | Vista General | 0 | 07-20-2008 12:01 PM |
| Goofed up GPT partition table... Data Lost? | __ | Vista file management | 0 | 07-20-2008 12:01 PM |
| Adding data to a hash table | NeilOz | PowerShell | 3 | 12-27-2007 09:32 PM |
| Creating files from Data Table | Shadow | PowerShell | 1 | 03-15-2007 08:46 AM |
| How do I get format-table to drop that omission points (...) and display my data | Harald Ums | PowerShell | 8 | 06-04-2006 08:20 AM |