<% Dim conn,rs,rs2,sqlstr,t_count,table_name,i On error resume next Set conn = Server.CreateObject("ADODB.Connection") Conn.Connectionstring="provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath("cwycms.mdb") Conn.open If err then Response.write "请检查数据库路径!" err.clear Response.End End if T_count = 0 Set rs = Conn.openschema(20) Do while not rs.eof If rs("table_type")="TABLE" then T_count = T_count + 1 table_name = rs("table_name") Response.write "<b>表" & table_name & ":</b><br>" Sqlstr = "select * from " & table_name Set rs2 = Server.CreateObject("ADODB.RecordSet") Rs2.open sqlstr,conn,0,1 For i=0 to rs2.fields.count-1 If i = rs2.fields.count-1 then Response.write rs2.fields.item(i).name Else Response.write rs2.fields.item(i).name & "," End if Next Response.write "<p>" Rs2.close Set rs2 = nothing End if Rs.movenext Loop Response.write "<u><b>总计</b><font color=red>" & t_count & "</font><b>个表</b></u>" Rs.close Set rs = nothing Conn.close Set conn=nothing %>
其中主要是运用了Connection对象的openschema方法,这边要注意的是rs("table_type")="TABLE"一句中 TABLE一定要大写。