ASP如何读取ACCESS中字段说明?
在ACCESS中有设置字段名和说明,rs.fields(i).name读取的是字段名称,请问字段说明怎么读取ASP代码...
在ACCESS中有设置字段名和说明,rs.fields(i).name读取的是字段名称,请问字段说明怎么读取
ASP代码 展开
ASP代码 展开
4个回答
展开全部
1.asp如何获取access数据库的字段说明代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>提取access字段的说明信息</title>
</head>
<%
dim table
table = trim(request("t1"))
database=trim(request("d1"))
%>
<body>
<form method="POST" action="">
数据文件名:<input type="text" name="D1" size="40" value=<%response.write(database)%> >同目录下数据文件名称 如:database.mdb<br>
表......名:<input type="text" name="T1" size="40" value=<%response.write(table)%> >database.mdb中的表名<br>
<input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2">
</form>
<%
if table = "" then
response.write("post nothing")
else%><%
dim conn
dim connstr
on error resume next
connstr="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath(database)+";"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
response.write(connstr+"<br>")
dim sql
dim rs
sql="select * from "+table+""
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
response.write(sql+"<br>")
If rs.State = adStateOpen Then
cnnState = "open"
Else
cnnState = "closed"
End If
response.write(cnnState +"<br>")
response.write("列数:"+cstr(rs.fields.count)+"<br>")
For i=0 to rs.fields.count-1
Response.Write "<TH>"+ rs(i).Name +"</TH>;<br>"
Next
Dim MyTableName
Dim MyFieldName
Dim MyDB
set mydb=server.createobject("adox.catalog")
Dim MyTable
set mytable=server.createobject("adox.table")
Dim MyField
set myfield =server.createobject("adox.column")
Dim pro
On Error resume next
MyDB.ActiveConnection =conn
For Each MyTable In MyDB.Tables
For Each MyField In MyTable.Columns
'response.write "FieldName:" & FieldType(MyField.Type) & " FieldSize:" & MyField.DefinedSize 'FieldType(pro.Type)
'response.write table & "." & MyField.name &":" '呵呵这里有变动,以前的有误
response.write MyTable.name & "." & MyField.name &":" '呵呵这里有变动,以前的有误
For Each pro In MyField.Properties
if pro.name="Description" and pro.Value <> "" then response.write pro.Value & " <br> " 'MyTable.Name & " : " & MyField.Name & " : " & pro.Name & " : " & pro.Value
Next
Next
Next
rs.close()
conn.close()
end if
%>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>提取access字段的说明信息</title>
</head>
<%
dim table
table = trim(request("t1"))
database=trim(request("d1"))
%>
<body>
<form method="POST" action="">
数据文件名:<input type="text" name="D1" size="40" value=<%response.write(database)%> >同目录下数据文件名称 如:database.mdb<br>
表......名:<input type="text" name="T1" size="40" value=<%response.write(table)%> >database.mdb中的表名<br>
<input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2">
</form>
<%
if table = "" then
response.write("post nothing")
else%><%
dim conn
dim connstr
on error resume next
connstr="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath(database)+";"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
response.write(connstr+"<br>")
dim sql
dim rs
sql="select * from "+table+""
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
response.write(sql+"<br>")
If rs.State = adStateOpen Then
cnnState = "open"
Else
cnnState = "closed"
End If
response.write(cnnState +"<br>")
response.write("列数:"+cstr(rs.fields.count)+"<br>")
For i=0 to rs.fields.count-1
Response.Write "<TH>"+ rs(i).Name +"</TH>;<br>"
Next
Dim MyTableName
Dim MyFieldName
Dim MyDB
set mydb=server.createobject("adox.catalog")
Dim MyTable
set mytable=server.createobject("adox.table")
Dim MyField
set myfield =server.createobject("adox.column")
Dim pro
On Error resume next
MyDB.ActiveConnection =conn
For Each MyTable In MyDB.Tables
For Each MyField In MyTable.Columns
'response.write "FieldName:" & FieldType(MyField.Type) & " FieldSize:" & MyField.DefinedSize 'FieldType(pro.Type)
'response.write table & "." & MyField.name &":" '呵呵这里有变动,以前的有误
response.write MyTable.name & "." & MyField.name &":" '呵呵这里有变动,以前的有误
For Each pro In MyField.Properties
if pro.name="Description" and pro.Value <> "" then response.write pro.Value & " <br> " 'MyTable.Name & " : " & MyField.Name & " : " & pro.Name & " : " & pro.Value
Next
Next
Next
rs.close()
conn.close()
end if
%>
</body>
</html>
展开全部
用ADOX,百度百科一下有详细说明
另外,用ACCESS自带的VBA可以实现这个功能。
关键是引用ado.ext 控件,我不知道asp默认是不有安装了这个控件。
网上找到两个例子资料给你参考:
<%@ Language=VBScript %>
<%
'------- 利用ADOX取得Access中字段的说明 ---------------
Function OpenConnectionWithString(strMDBPath, strTableName, strColName)
Dim cat
Set cat = server.CreateObject("ADOX.Catalog")
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strMDBPath
OpenConnectionWithString = cat.Tables(strTableName).Columns(strColName).Properties("Description").Value
Set cat = Nothing
End Function
response.Write OpenConnectionWithString(server.MapPath("./数据库名称.mdb"), "表名称", "目标字段名称")
%>
'自己把自己的数据路径填写好,写好表名 和 目标字段名
************************************************************************************************
利用ADOX获取Access数据库字段的所有属性
2010-03-01 16:57:46| 分类: 微软VBA |字号 订阅
一直以来都用SQL语句来操作Access,但发现有些Access字段的属性不能用SQL来操作,在网上搜索了一些资料后,才了解了一些用ADOX设定字段的方法,为了方便了解这些字段的属性,就先自己建立一个Access数据库,然后创建好表与字段,设置好这字段的属性,然后后用下面的程序把它的属性例出到Excel中来,此程序需要引用ADOX。
Dim MyCat As ADOX.Catalog
Dim MyTab As ADOX.Table
Dim MyCol As ADOX.Column
Dim MyPro As ADOX.Property
Dim tSh As Worksheet
Dim i As Long
Dim DataName As String, PassStr As String, TableName As String
DataName = "Excel吧" '数据库名称
DataName = ThisWorkbook.Path & "\" & DataName & ".mdb"
If Dir(DataName) = "" Then
MsgBox "数据库:" & DataName & "不存在!"
Exit Sub
End If
PassStr = "" '数据库密码
TableName = "数据表2" '数据表名称
Set tSh = ThisWorkbook.Worksheets.Add
tSh.Range("A1:D1") = Array("字段名称", "字段类型", "字段属性", "属性值")
Set MyCat = New ADOX.Catalog
MyCat.ActiveConnection = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & _
DataName & ";Jet OLEDB:Database Password=" & MyPass
Set MyTab = New ADOX.Table
Set MyTab = MyCat.Tables(TableName)
i = 2
For Each MyCol In MyTab.Columns
tSh.Cells(i, 1) = MyCol.Name
tSh.Cells(i, 2) = MyCol.Type
For Each MyPro In MyCol.Properties
tSh.Cells(i, 3) = MyPro.Name
tSh.Cells(i, 4) = MyPro.Value
i = i + 1
Next
Next
tSh.Cells.EntireColumn.AutoFit
MsgBox "字段信息读取完毕!", , "提示"
End Sub
请自己修改程序中的数据库名,密码与数据表名,路径为包含程序的Excel文件的目录中。
从程序的运行结果可以看到,列举的属性有:
0 Autoincrement 自动编号
1 Default 默认值
2 Description
3 Nullable 必填字段
4 Fixed Length
5 Seed
6 Increment
7 Jet OLEDB:Column Validation Text 有效性文本
8 Jet OLEDB:Column Validation Rule 有效性规则
9 Jet OLEDB:IISAM Not Last Column
10 Jet OLEDB:AutoGenerate
11 Jet OLEDB:One BLOB per Page
12 Jet OLEDB:Compressed UNICODE Strings
13 Jet OLEDB:Allow Zero Length 允许空字符串
14 Jet OLEDB:Hyperlink 超链接型
另外,用ACCESS自带的VBA可以实现这个功能。
关键是引用ado.ext 控件,我不知道asp默认是不有安装了这个控件。
网上找到两个例子资料给你参考:
<%@ Language=VBScript %>
<%
'------- 利用ADOX取得Access中字段的说明 ---------------
Function OpenConnectionWithString(strMDBPath, strTableName, strColName)
Dim cat
Set cat = server.CreateObject("ADOX.Catalog")
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strMDBPath
OpenConnectionWithString = cat.Tables(strTableName).Columns(strColName).Properties("Description").Value
Set cat = Nothing
End Function
response.Write OpenConnectionWithString(server.MapPath("./数据库名称.mdb"), "表名称", "目标字段名称")
%>
'自己把自己的数据路径填写好,写好表名 和 目标字段名
************************************************************************************************
利用ADOX获取Access数据库字段的所有属性
2010-03-01 16:57:46| 分类: 微软VBA |字号 订阅
一直以来都用SQL语句来操作Access,但发现有些Access字段的属性不能用SQL来操作,在网上搜索了一些资料后,才了解了一些用ADOX设定字段的方法,为了方便了解这些字段的属性,就先自己建立一个Access数据库,然后创建好表与字段,设置好这字段的属性,然后后用下面的程序把它的属性例出到Excel中来,此程序需要引用ADOX。
Dim MyCat As ADOX.Catalog
Dim MyTab As ADOX.Table
Dim MyCol As ADOX.Column
Dim MyPro As ADOX.Property
Dim tSh As Worksheet
Dim i As Long
Dim DataName As String, PassStr As String, TableName As String
DataName = "Excel吧" '数据库名称
DataName = ThisWorkbook.Path & "\" & DataName & ".mdb"
If Dir(DataName) = "" Then
MsgBox "数据库:" & DataName & "不存在!"
Exit Sub
End If
PassStr = "" '数据库密码
TableName = "数据表2" '数据表名称
Set tSh = ThisWorkbook.Worksheets.Add
tSh.Range("A1:D1") = Array("字段名称", "字段类型", "字段属性", "属性值")
Set MyCat = New ADOX.Catalog
MyCat.ActiveConnection = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & _
DataName & ";Jet OLEDB:Database Password=" & MyPass
Set MyTab = New ADOX.Table
Set MyTab = MyCat.Tables(TableName)
i = 2
For Each MyCol In MyTab.Columns
tSh.Cells(i, 1) = MyCol.Name
tSh.Cells(i, 2) = MyCol.Type
For Each MyPro In MyCol.Properties
tSh.Cells(i, 3) = MyPro.Name
tSh.Cells(i, 4) = MyPro.Value
i = i + 1
Next
Next
tSh.Cells.EntireColumn.AutoFit
MsgBox "字段信息读取完毕!", , "提示"
End Sub
请自己修改程序中的数据库名,密码与数据表名,路径为包含程序的Excel文件的目录中。
从程序的运行结果可以看到,列举的属性有:
0 Autoincrement 自动编号
1 Default 默认值
2 Description
3 Nullable 必填字段
4 Fixed Length
5 Seed
6 Increment
7 Jet OLEDB:Column Validation Text 有效性文本
8 Jet OLEDB:Column Validation Rule 有效性规则
9 Jet OLEDB:IISAM Not Last Column
10 Jet OLEDB:AutoGenerate
11 Jet OLEDB:One BLOB per Page
12 Jet OLEDB:Compressed UNICODE Strings
13 Jet OLEDB:Allow Zero Length 允许空字符串
14 Jet OLEDB:Hyperlink 超链接型
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Access 好像不行啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
字段说明? 要读这个干嘛? ado引擎也许不读这个信息
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询