ASP如何读取ACCESS中字段说明?
答案:4 悬赏:80 手机版
解决时间 2021-12-01 09:04
- 提问者网友:骑士
- 2021-11-30 17:27
ASP如何读取ACCESS中字段说明?
最佳答案
- 五星知识达人网友:独钓一江月
- 2021-11-30 19:06
1.asp如何获取access数据库的字段说明代码如下:
提取access字段的说明信息
<%
dim table
table = trim(request("t1"))
database=trim(request("d1"))
%>
<%
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+"
")
dim sql
dim rs
sql="select * from "+table+""
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
response.write(sql+"
")
If rs.State = adStateOpen Then
cnnState = "open"
Else
cnnState = "closed"
End If
response.write(cnnState +"
")
response.write("列数:"+cstr(rs.fields.count)+"
")
For i=0 to rs.fields.count-1
Response.Write ""+ rs(i).Name +" ;
"
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 & "
" 'MyTable.Name & " : " & MyField.Name & " : " & pro.Name & " : " & pro.Value
Next
Next
Next
rs.close()
conn.close()
end if
%>
<%
dim table
table = trim(request("t1"))
database=trim(request("d1"))
%>
<%
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+"
")
dim sql
dim rs
sql="select * from "+table+""
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
response.write(sql+"
")
If rs.State = adStateOpen Then
cnnState = "open"
Else
cnnState = "closed"
End If
response.write(cnnState +"
")
response.write("列数:"+cstr(rs.fields.count)+"
")
For i=0 to rs.fields.count-1
Response.Write "
"
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 & "
" 'MyTable.Name & " : " & MyField.Name & " : " & pro.Name & " : " & pro.Value
Next
Next
Next
rs.close()
conn.close()
end if
%>
全部回答
- 1楼网友:渊鱼
- 2021-11-30 21:31
字段说明? 要读这个干嘛? ado引擎也许不读这个信息
- 2楼网友:行路难
- 2021-11-30 20:14
Access 好像不行啊
- 3楼网友:过活
- 2021-11-30 20:03
用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 超链接型
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯