在ASP中列出数据库中的表名和字段名的程序

发表于:2007-06-30来源:作者:点击数: 标签:
% dsn = DSN=DSNName Const adSchemaTables = 20 adSchemaColumns = 4 Set oConn = Server.CreateObject(ADODB.Connection) oConn.open dsn Set rstSchema = oConn.OpenSchema(adSchemaColumns) response.write table response.write tr td Table name/tdtdfi
<%
dsn = "DSN=DSNName"
Const adSchemaTables = 20
adSchemaColumns = 4
Set oConn = Server.CreateObject("ADODB.Connection")

oConn.open dsn
Set rstSchema = oConn.OpenSchema(adSchemaColumns)
response.write "<table>"
response.write "<tr><td>Table name</td><td>field name</td><td>field type</td><td>is nullable</td><td>field size</td></tr>"
tablename=""
Do Until rstSchema.EOF
response.write "<tr><td>"
if rstSchema("Table_name") <> tablename then
response.write rstSchema("Table_name")
tablename = rstSchema("Table_name")
else
response.write " "
end if
response.write "</td><td>"& rstschema("column_Name") & "</td><td>"
select case rstschema("data_type")
case "130"
if rstschema("CHARACTER_MAXIMUM_LENGTH") = 1073741823 then
response.write "Memo"
else
response.write "Text"
end if
case 135
response.write "Date/Time"
case 3
response.write "Long Integer"
case 11
response.write "Yes/No"
case 131
response.write "Currency"
case else
response.write rstschema("data_type")
end select
response.write "</td><td>" & rstschema("is_nullable") & "</td><td>"
if rstschema("CHARACTER_MAXIMUM_LENGTH") <> 1073741823 then
response.write rstschema("CHARACTER_MAXIMUM_LENGTH")
else
response.write " "
end if
response.write "</td></tr>"
rstSchema.MoveNext
Loop
response.write "</table>"
%>

原文转自:http://www.ltesting.net