怎样把数据库结构显示出来的源代码

通过以上的代码即可显示表的结构,字段类型,长度,自动编号,主健。如果你仔细研究后就可以发现如何远程改变数据库的结构了,祝你好运!

要查看此演示,需要你建立一个数据源,request("table")改为你的表的名字。

1<html>
2<head>
3<title>main</title>
4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
5</head>
6<body bgcolor="#CCCCCC" text="#000000">
7<h2 align="center"><font face="华文新魏">欢迎查看chenyangasp演示程序</font></h2>
8<p>   

on error resume next
table=request("table")
//获得表名
if table&lt;&gt;"" then
response.write "数据表:"&amp;table
Set primary = con.OpenSchema(adSchemaPrimaryKeys, _
Array(empty, empty, table))
if primary("COLUMN_NAME")&lt;&gt;"" then
primarykey=primary("COLUMN_NAME")
end if
primary.close
set primary=nothing

 1</p>
 2<center>
 3<table border="1" cellpadding="0" cellspacing="0" width="650">
 4<tr bgcolor="#CCCCCC">
 5<th class="sundog" width="61">
 6<div align="center">字段</div>
 7</th>
 8<th class="sundog" width="131">
 9<div align="center">类型</div>
10</th>
11<th class="sundog" width="105">
12<div align="center">设定大小</div>
13</th>
14<th class="sundog" width="69">
15<div align="center">允许空值</div>
16</th>
17<th class="sundog" width="69">   
18自动编号   
19</th>
20<th class="sundog" width="81">主键</th>
21</tr>   

sql="select * from ["&amp;table&amp;"] "
set rs=con.execute(sql)
for i=0 to rs.fields.count-1

1<tr bgcolor="#CCCCCC">
2<td class="sundog" height="2" width="61">
3<div align="center">```
4=rs(i).name
5```</div>   
6//字段名   
7</td>
8<td class="sundog" height="2" width="131">
9<div align="center">   

field_type=rs(i).type
select case field_type
case adEmpty
typ = "Empty"
case adTinyInt
typ = "TinyInt"
case adSmallInt
typ = "SmallInt"
case adInteger
typ = "Integer"
case adBigInt
typ = "BigInt"
case adUnsignedTinyInt
typ = "UnsignedTinyInt"
case adUnsignedSmallInt
typ = "UnsignedSmallInt"
case adUnsignedInt
typ = "UnsignedInt"
case adUnsignedBigInt
typ = "UnsignedBigInt"
case adSingle
typ = "Single"
case adDouble
typ = "Double"
case adCurrency
typ = "Currency"
case adDecimal
typ = "Decimal"
case adNumeric
typ = "Numeric"
case adBoolean
typ = "Boolean"
case adError
typ = "Error"
case adUserDefined
typ = "UserDefined"
case adVariant
typ = "Variant"
case adIDispatch
typ = "IDispatch"
case adIUnknown
typ = "IUnknown"
case adGUID
typ = "GUID"
case adDATE
typ = "DATE"
case adDBDate
typ = "DBDate"
case adDBTime
typ = "DBTime"
case adDBTimeStamp
typ = "DBTimeStamp"
case adBSTR
typ = "BSTR"
case adChar
typ = "Char"
case adVarChar
typ = "VarChar"
case adLongVarChar
typ = "LongVarChar"
case adWChar
typ = "WChar"
case adVarWChar
typ = "VarWChar"
case adLongVarWChar
typ = "LongVarWChar"
case adBinary
typ = "Binary"
case adVarBinary
typ = "VarBinary"
case adLongVarBinary
typ = "LongVarBinary"
case adChapter
typ = "Chapter"
case adPropVariant
typ = "PropVariant"
case else
typ = "Unknown"
end select
response.write typ

 1//字段类型   
 2</div>
 3</td>
 4<td class="sundog" height="2" width="105">
 5<div align="center">```
 6=rs(i).definedsize
 7```</div>
 8</td>   
 9//字段长度   
10  
11<td class="sundog" height="2" width="69">
12<div align="center">   

attrib=rs(i).attributes
if (attrib and adFldIsNullable)=0 then
response.write "No"
else
response.write "Yes"
end if

1</div>
2</td>   
3  
4//是否允许空值   
5  
6<td class="sundog" height="2" width="69">
7<div align="center">   

if rs(i).Properties("ISAUTOINCREMENT") = True then

1<input checked="" name="autoincrement" type="checkbox" value="checkbox"/>   

else

1<input name="autoincrement" type="checkbox" value="checkbox"/>   

end if

1</div>
2</td>   
3  
4//是否为自动编号   
5  
6<td class="sundog" height="2" width="81">
7<div align="center">   

if rs(i).name=primarykey then

1<input checked="" name="primarykey" type="checkbox" value="checkbox"/>   

else

1<input name="primarykey" type="checkbox" value="checkbox"/>   

end if

1</div>
2</td>   
3  
4//主健   
5  
6</tr>   

next

1</table>
2</center></body></html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus