1
<%
2
Dim conn,rs,rs2,sqlstr,t_count,table_name,i
3
On error resume next
4
Set conn = Server.CreateObject("ADODB.Connection")
5
Conn.Connectionstring="provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath("data1.mdb")
6
Conn.open
7
If err then
8
Response.write "请检查数据库路径!"
9
err.clear
10
Response.End
11
End if
12
T_count = 0
13
Set rs = Conn.openschema(20)
14
Do while not rs.eof
15
If rs("table_type")="TABLE" then
16
T_count = T_count + 1
17
table_name = rs("table_name")
18
Response.write "<b>表" & table_name & ":</b><br>"
19
Sqlstr = "select * from " & table_name
20
Set rs2 = Server.CreateObject("ADODB.RecordSet")
21
Rs2.open sqlstr,conn,0,1
22
For i=0 to rs2.fields.count-1
23
If i = rs2.fields.count-1 then
24
Response.write rs2.fields.item(i).name
25
Else
26
Response.write rs2.fields.item(i).name & ","
27
End if
28
Next
29
Response.write "<p>"
30
Rs2.close
31
Set rs2 = nothing
32
End if
33
Rs.movenext
34
Loop
35
Response.write "<u><b>总计</b><font color=red>" & t_count & "</font><b>个表</b></u>"
36
Rs.close
37
Set rs = nothing
38
Conn.close
39
Set conn=nothing
40
%>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
其中主要是运用了Connection对象的openschema方法,这边要注意的是rs("table_type")="TABLE"一句中TABLE一定要大写。此方法在ASP教材中很少看到,搜索了大量资料后我还不是非常了解,下边是我搜索到的两篇相关文章,有兴趣的朋友可以看看:
1.http://dev.csdn.net/article/68/68466.shtm
2.http://fishcat.blog.com.cn/archives/2006/386828.shtml