Search Tools Links Login

Display table from mdb as html


Often I use flat mdb files to post forms to on the webserver. This is a simple page to just grab a table from an mdb file on the server with a DSN-less connection and display it as an HTML table, so I can copy the table and paste it into Excel or Access, or just to get a quick look at the contents.

Original Author: Jim Tinney

Inputs

Database file path, Table name

Assumptions

Shows use of ADO to get data and dynamically construct a table.

Returns

HTML table in browser of all columns / rows in an access db table.

Code

<%@ Language=VBScript %>

Database Table Contents
<%
''Get the data from an access databse on the web server
''DSN-Less connection to local access db
dim Myconn,MyRS,MyField,MyRecord,DSNstr,SQLstr
set conn = server.CreateObject("adodb.connection")
set MyRS = server.CreateObject("adodb.recordset")
DSNstr="DRIVER={Microsoft Access Driver (*.mdb)}; "
      DSNstr=DSNstr & "DBQ=" & "e:wwwrootdatabases hing2.mdb"
''Change this to the path to your db file ^^^^^^^^^^^^^^^^^^^^^
  Myconn.Open DSNstr
   SQLstr = "SELECT * FROM results"
''Change this to your table name ^^^ (here it's "results")
Set MyRS = Myconn.execute(SQLstr)
''You can send in the dbpath and tablename as parameters
''by simply calling the page like so:
''http://myserver/mydir/gettable.asp?db="e:wwwrootdatabases hing2.mdb"&table="results"
''Then replace the strings above with
''    DSNstr=DSNstr & "DBQ=" & Request.Querystring("db")
''and
''    SQLstr = "SELECT * FROM " & Request.Querystring("table")
''This is not a very pretty table, meant mostly
''to get the table so you can copy it and paste
''it into Excel or something. Add formatting, widths,
''fonts, etc., to make it pretty.
response.Write "

"
MyRS.MoveFirst
For Each MyField In MyRS.Fields
response.Write "
"
Next 'MyField
response.Write "
"
While not MyRS.EOF
response.Write "
"
  For Each MyField In MyRS.Fields
   response.Write "
"
  Next 'MyField
response.Write "
"
MyRS.MoveNext
Wend
response.Write "
"
response.Write MyField.Name
response.Write "
"
   response.Write MyField.Value
   response.Write "
"
''Close up objects
Set MyRS= Nothing
conn.Close
set conn = nothing
''Simple, Huh?
%>

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 92 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.