Advertisement
6_2008-2009 String Manipulation #209451

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.

AI

AI 요약: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

소스 코드
original-source
<%@ Language=VBScript %>
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Database Table Contents</TITLE></HEAD><BODY>
<% 
''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:\wwwroot\databases\thing2.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:\wwwroot\databases\thing2.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 "<table border=1><tr>"
MyRS.MoveFirst
For Each MyField In MyRS.Fields
 response.Write "<td>"
 response.Write MyField.Name
 response.Write "</td>"
Next 'MyField
response.Write "</tr>"
While not MyRS.EOF
 response.Write "<tr>"
  For Each MyField In MyRS.Fields
   response.Write "<td>"
   response.Write MyField.Value
   response.Write "</td>"
  Next 'MyField
 response.Write "</tr>"
 MyRS.MoveNext
Wend
response.Write "</table>"
''Close up objects
	Set MyRS= Nothing
	conn.Close
	set conn = nothing
''Simple, Huh?
%>
</BODY></HTML>
원본 댓글 (3)
Wayback Machine에서 복구됨