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

来源:asp之家 时间:2011-04-15 10:50:00 


<html> 
<head> 
<title>获取ACCESS数据库表名 - www.cidianwang.com</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 
%>

标签:ASP,ACCESS表名
0
投稿

猜你喜欢

  • Oracle 自增(auto increment) 或 标识字段的建立方法

    2009-03-06 11:15:00
  • Web 标准设计实践:Google 的首页

    2008-10-12 12:14:00
  • js友好的表单验证程序vform

    2007-08-16 13:32:00
  • javascript用回车键实现Tab键功能

    2009-07-05 18:40:00
  • 在原窗口还是新窗口打开链接?

    2009-12-07 21:24:00
  • 编写一个JS组件来说说call和apply的用法

    2008-11-23 17:11:00
  • MHTML在ie7/vista bug 解决方案

    2010-02-01 12:42:00
  • JavaScript 各种动画渐变效果

    2008-09-02 10:38:00
  • ASP对FoxPro自由表(DBF文件)的操作

    2010-05-27 12:20:00
  • 利用不同样式改变相同xhtml结构的布局

    2008-08-20 18:17:00
  • Sql Server 2005数据库被标记为“可疑”问题

    2009-12-15 10:50:00
  • 数据库中identity字段不必是系统产生的唯一值 性能优化方法(新招)

    2011-09-30 11:26:06
  • sqlserver中如何查询出连续日期记录的代码

    2011-09-30 11:16:56
  • SQL Server 作业的备份(备份作业非备份数据库)

    2012-07-11 15:58:49
  • 如何修改Linux的下MySQL 5.0的默认连接数

    2012-01-29 18:07:04
  • 有关Oracle数据库的备份情况

    2010-07-30 13:21:00
  • 一个网页设计师的成长经历

    2008-05-27 12:38:00
  • 最近写的一个asp缓存函数

    2008-11-25 14:07:00
  • MySQL6.0新增特性

    2010-03-25 10:08:00
  • sql 自定义百分比转换小数函数代码

    2011-09-30 11:54:01
  • asp之家 网络编程 m.aspxhome.com