|
CodeAve.com - ASP - Database Table Display | ||||
|
|
||||
| Display an Excel DB | |||||
|
|
|||||
<html> <title>CodeAve.com(Display an Excel in ASP)</title> <body bgcolor="#FFFFFF"> <!--#include file="adovbs.inc"--> <% ' Import constants from adovbs.inc specifically 'adOpenStatic and adLockPessimistic 'Name of the excel file being displayed exceldb="greenberg.xls" ' Create a server connection object Set cn = Server.CreateObject("ADODB.Connection") cn.Open "DBQ=" & Server.MapPath(exceldb) & ";" & _ "DRIVER={Microsoft Excel Driver (*.xls)};" ' Create a server recordset object Set rs = Server.CreateObject("ADODB.Recordset") ' Query to run against the exceldb ' hamerin_hank is the name of the ' cell range as defined in excel sql="select * from hammerin_hank;" ' Execute the sql rs.Open sql, cn, _ adOpenStatic, adLockPessimistic %> <table border=1 align=center> <caption>Hank Greenberg Career Statistics</caption><% For counter = 0 To rs.fields.count - 1 %> <th> <% ' Write out the field names response.write rs.fields.item(counter).name %> </th><% ' Move to the next field next ' Move to the first record rs.movefirst ' Write out the record set do while not rs.eof %> <tr><% ' Loop through all of the fileds for counter = 0 to rs.fields.count - 1 %> <td align=right> <% ' Write out the field values response.write rs.fields.item(counter).value %> </td><% ' Move to the next field next %> </tr><% ' Move to the next record rs.movenext loop %> </table> <% ' Kill the recordset rs.close Set rs = nothing ' Kill the connection cn.close Set cn = nothing %> </body> </html>
|
|||||
|
|
|||||