ASP遍历Access数据库表结构

ASP遍历Access数据库表结构
源码如下:

<%
Acc_db = "db.mdb" 
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(Acc_db) 
Set conn = CreateObject("ADODB.Connection")
conn.CursorLocation = 3
conn.open connstr
%>
<%Set RST = conn.OpenSchema(20)
  Do Until RST.EOF
   response.write "表:"&RST("TABLE_NAME")&"&nbsp&nbsp类型:"&RST("TABLE_TYPE")&"<br>"
  
 if RST("TABLE_TYPE")="TABLE" then %>
   <br/>  
<table border="1" width="100%" cellspacing="0" cellpadding="0">
  <tr height=25>
   <td align=center bgcolor="#ECF2FC">字段名</td>
   <td align=center bgcolor="#ECF2FC">属性</td>
   <td align=center bgcolor="#ECF2FC">允许长度或取值范围</td>
   </tr><tr>
<%
set rs=conn.execute("select * from "& RST("TABLE_NAME") )
 'rs.open   sql,conn,3,1

 for i=0 to rs.fields.count-1  
 response.write("<td align=center><font color=blue>"&rs.fields(i).name&"</font></td>")
 
action=rs.fields(i).type
select case action
case"2" thetypename="<font color=red>整型数字</font>"
case"3" thetypename="<font color=red>自动编号</font>"
case"4" thetypename="<font color=ff9933>单精度型数字</font>"
case"7" thetypename="<font color=66ff33>日期/时间</font>"
case"11" thetypename="<font color=009933>逻辑是否型</font>"
case"202" thetypename="<font color=996633>有限长文本型</font>"
case"203" thetypename="备注文本型"
end select          
response.write("<td align=center>"&thetypename&"</td>")
if rs.fields(i).type=2 then yxcd="-32768~32767"
if rs.fields(i).type=4 then yxcd="-3.4E38~3.4E38"
if rs.fields(i).type=7 then  yxcd="常规时间"
if rs.fields(i).type<>2 and rs.fields(i).type<>4 and rs.fields(i).type<>7 then yxcd=rs.fields(i).DefinedSize
 response.write("<td align=center>"&yxcd&"</td>")
response.write("</tr><tr>")
      next  
      rs.close  
      set rs=nothing 
          
%>
</table>
<%end if
RST.MoveNext
Loop
RST.close
Set RST = nothing
conn.close
set conn = nothing%>

本博客所有文章如无特别注明均为原创。作者:sysdee复制或转载请以超链接形式注明转自 成功志
原文地址《ASP遍历Access数据库表结构
分享到:更多

相关推荐

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)