ASP Read database fields

Source: Internet
Author: User

Today came up with the idea of using ASP to get all the table names in the database, the field names of all the tables, and the contents of all the fields in the database only if you know the names of the databases. After a period of time to query information and changes, and finally made out, now share with you.
<%
' function: Display the table name, field name, field contents in the database
' Original: Wangsdong
' Source: www.111cn.net
' original article, reprint please keep this information, thank you
% >
Just change the database name and run the program, and you'll see the results.

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 "Table name:" &rs (2) & "
"
Set Rs1=server. CreateObject ("Adodb.recordset")
Sql= "SELECT * from" &rs (2)
Set rs1=conn.execute (SQL)
Response.Write "Field Name:"
For I=0 to Rs1.fields.count-1
Response.Write Rs1.fields (i) .name& ""
Next
Response.Write "
"

Do as 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

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.