微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用Asp读取Access的数据表

<html>

<head>

<% 

dim connstr,primary

dim datapath,con 

dataPath=server.mappath("data.mdb")

connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&dataPath

Set con = Server.CreateObject("ADODB.Connection")

con.Open connstr

Const adSchemaViewTableusage = 25

Const adSchemaProcedureParameters = 26

Const adSchemaForeignKeys = 27

Const adSchemaPrimaryKeys = 28

Const adSchemaProcedureColumns = 29

%>

<title>main</title>

<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<body bgcolor="#CCCCCC" text="#000000">

<% 'on error resume next

set primary=server.createobject("adodb.recordset")

table="title" '获得表名

'table="choice"

'table="manage"

if table<>"" then response.write "数据表:"&table

Set primary = con.OpenSchema(adSchemaPrimaryKeys)

if primary("COLUMN_NAME")<>"" then

primarykey=primary("COLUMN_NAME")

response.Write(primarykey)

end if

primary.close

set primary=nothing

%>

</p>

<center>

<table width="650" border="1" cellpadding="0" cellspacing="0">

<tr bgcolor="#CCCCCC">

<th class="sundog" width="61"> <div align="center">字段</div></th>

<th class="sundog" width="131"> <div align="center">类型</div></th>

<th class="sundog" width="105"> <div align="center">设定大小</div></th>

<th class="sundog" width="69"> <div align="center">允许空值</div></th>

<th class="sundog" width="69"> 自动编号 </th>

<th class="sundog" width="81">主键</th>

</tr>

<%sql="select * from ["&table&"] "

set rs=con.execute(sql)

for i=0 to rs.fields.count-1 %>

<tr bgcolor="#CCCCCC">

<td class="sundog" height="2" width="61"><div align="center"><%=rs(i).name%></div>

<!--//字段名--> </td>

<td class="sundog" height="2" width="131"><div align="center">

<%

adBigInt=20

adBinary =128

adBoolean=11

adChar=129

adDBTimeStamp=135

adEmpty=0

adInteger=3

adSmallInt=2

adtinyint=16

adVarChar=200

adVarWChar=202

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

response.write field_type%>

<!--字段类型--> </div></td>

<td class="sundog" height="2" width="105"><div align="center"><%=rs(i).definedsize%></div></td>

<!--字段长度-->

<td class="sundog" height="2" width="69"><div align="center">

<% attrib=rs(i).attributes

if (attrib and adFldisNullable)=0 then

response.write "No"

else response.write "Yes"

end if %>

</div></td>

<!--//是否允许空值-->

<td class="sundog" height="2" width="69"><div align="center">

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

<input type="checkBox" name="autoincrement" value="checkBox" checked>

<%else%>

<input type="checkBox" name="autoincrement" value="checkBox">

<%end if%>

</div></td>

<!--//是否为自动编号-->

<td class="sundog" height="2" width="81"><div align="center">

<%'response.Write(rs(i).name)%>

<%if UCase(rs(i).name)=UCase(primarykey) then%>

<input type="checkBox" name="primarykey" value="checkBox" checked>

<%else%>

<input type="checkBox" name="primarykey" value="checkBox">

<%end if%>

</div></td>

<!--//主健--> </tr>

<%next %>

</table>

</center>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐