Code for ASP to obtain the name and structure of an ACCESS database table

Source: Internet
Author: User


<Html>
<Head>
<Title> obtain ACCESS database table name_www.jb51.net </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">
Database path: <input type = "text" name = "path" value = "" size = "50"/>
<Input type = "hidden" name = "ari" value = "1"/>
<Input type = "submit" value = "View"/>
</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 "database connection error. Check the connection string. "
Response. End
End If
%>
<Font color = red> <% = conn. connectionstring %> </font> <%
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': filter out the hidden table here.
J = j + 1
Call GetFileds (shm ("table_name "))
End If
End If
Shm. MoveNext
Loop
Response. write "Total" & j & "data tables! "
Else
Response. write "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 "Table <font color = red> <B>" & TableName & "</B> </font> contains" & Cont & "fields, as follows: <br> "& vbcrlf
For I = 0 To Cont-1
Dim filtype
Select case rs. fields (I). type
Case 3
Filtype = "automatic number (number )"
Case 1, 202
Filtype = "character"
Case 1, 203
Filtype = "Remarks"
Case 1, 125
Filtype = "date"
Case 11
Filtype = "True/false (yes/no )"
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
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.