欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP获取ACCESS数据库表名及结构的代码

程序员文章站 2022-07-01 23:36:15
获取access数据库表名_www.jb51.net

<html>
<head>
<title>获取access数据库表名_www.jb51.net</title>
</head>
<body style="text-align:left;margin-left:50px;font-family:'arial';font-size:12px">
<form style="padding:5px;margin:5px;margin-left:0px" name="get" action="" method="post">
数据库路径:<input type="text" name="path" value="" size="50" />
<input type="hidden" name="ari" value="1" />
<input type="submit" value="查看" />
</form>
<hr>
<%
if request.form("ari")="1" and request.form("path")<>"" then
dim conn,connstr,i,sql,rs
on error resume next
connstr="driver=microsoft access driver (*.mdb);dbq="+server.mappath(request.form("path"))
set conn=server.createobject("adodb.connection")
conn.open connstr
if err then
err.clear
set conn = nothing
response.write "数据库连接出错,请检查连接字串。"
response.end
end if
%>
<font color=red><%=conn.connectionstring%></font><hr>
<%
j=0
dim tablecount
tablecount=0
set shm = conn.openschema(20)
shm.movefirst
do while not shm.eof
if shm("table_type") = "table" then
if left(shm("table_name"), 1) <> "~" then '这里过滤掉隐藏表
j=j+1
call getfileds(shm("table_name"))
end if
end if
shm.movenext
loop
response.write "共有 "&j&" 个数据表!"
else
response.write "<h3>请输入数据库相对路径查看具体内容!</h3>"
end if
%>
</body>
</html>
<%
function getfileds(tablename)
set rs = server.createobject("adodb.recordset")
dim sql
sql = "select * from " & tablename
rs.open sql, conn, 1, 1
dim cont
cont = rs.fields.count
response.write "<div style=""margin-bottom:10px;padding:5px;border:1px #dddddd solid;background:#eeeeee"">"&vbcrlf
response.write "表 <font color=red><b>"&tablename&"</b></font> 中含有"&cont&"个字段,具体如下:<br>"&vbcrlf
for i = 0 to cont - 1
dim filtype
select case rs.fields(i).type
case 3
filtype="自动编号(数字)"
case 202
filtype="字符"
case 203
filtype="备注"
case 125
filtype="日期"
case 11
filtype="真/假(是/否)"
end select
response.write " <font color=red>"&i&"</font>--<font color=green><b>"&rs.fields(i).name&"</b></font>--"&filtype&";<br />"&vbcrlf
next
response.write "</div>"&vbcrlf
rs.close
set rs=nothing
end function
%>