asp读取mdb数据库所有表名的代码

[ 2012-10-24 12:17:23 | 作者: admin ]
字号: | |
第一个文件:adovbs.inc:
<%
'---- SchemaEnum Values ----
Const adSchemaProviderSpecific = -1
Const adSchemaAsserts = 0
Const adSchemaCatalogs = 1
Const adSchemaCharacterSets = 2
Const adSchemaCollations = 3
Const adSchemaColumns = 4
Const adSchemaCheckConstraints = 5
Const adSchemaConstraintColumnUsage = 6
Const adSchemaConstraintTableUsage = 7
Const adSchemaKeyColumnUsage = 8
Const adSchemaReferentialContraints = 9
Const adSchemaTableConstraints = 10
Const adSchemaColumnsDomainUsage = 11
Const adSchemaIndexes = 12
Const adSchemaColumnPrivileges = 13
Const adSchemaTablePrivileges = 14
Const adSchemaUsagePrivileges = 15
Const adSchemaProcedures = 16
Const adSchemaSchemata = 17
Const adSchemaSQLLanguages = 18
Const adSchemaStatistics = 19
Const adSchemaTables = 20
Const adSchemaTranslations = 21
Const adSchemaProviderTypes = 22
Const adSchemaViews = 23
Const adSchemaViewColumnUsage = 24
Const adSchemaViewTableUsage = 25
Const adSchemaProcedureParameters = 26
Const adSchemaForeignKeys = 27
Const adSchemaPrimaryKeys = 28
Const adSchemaProcedureColumns = 29
%>




实现文件read.asp
connstr="dbq="&server.mappath("db\mdate.mdb")&";driver={microsoft access driver (*.mdb)};"

          set conn=server.createobject("adodb.connection")
          conn.open connstr
          set rs = conn.OpenSchema(adSchemaTables)%>
<p class="sundog">table:</p>
<table width="120" border="0" cellpadding="0" cellspacing="0">
    <%do while not rs.eof
    if rs("table_type") = "TABLE" then%>
    <tr>
        <td class="sundog">
<a href="main.asp?table=<%=rs("table_name")%>"><%=rs("table_name")%></a>
</td>
    </tr>
    <%end if
    rs.movenext
    loop%>
</table>





===================其他一个完整实例代码=====================
引用
< %
'功能:显示数据库中表名、字段名、字段内容
'原创:wangsdong
'来源:aspprogram.cn
'原创文章,转载请保留此信息,谢谢

set rs=server.CreateObject("adodb.recordset")
db="db1.mdb"
set conn=server.CreateObject("adodb.connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
conn.open connstr

Set rs=Conn.OpenSchema(20)
Do Until rs.EOF

If rs(3)="TABLE" Then
response.write "表名:"&rs(2)&"<br />"
Set rs1=server.CreateObject("adodb.recordset")
sql="select * from "&rs(2)
Set rs1=conn.execute(sql)
response.write "字段名:"
For i=0 To rs1.fields.count-1
response.write rs1.fields(i).name&" "
Next
response.write "<br />"

Do While Not rs1.eof
response.write " "
For i=0 To rs1.fields.count-1
t=rs1.fields(i).name
response.write rs1(t)&" "
Next
response.write " "
rs1.movenext
Loop
response.write " "
End If

rs.MoveNext
Loop

Set rs=Nothing
Set conn=nothing
% >
[最后修改由 admin, 于 2012-10-24 12:29:27]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1888

这篇日志没有评论。

此日志不可发表评论。