我正在开发一个函数来从查询中获取数据。我想在我的数据之前同时拥有字段名称(DB中相同)和字段描述。我找到了如何获得字段名称,但我找不到获取描述的方法,有人可以帮助我吗?
这是我当前获取字段名称的代码(以及我如何评论说明):
'-Get the table's data
Set rs = con.Execute("SELECT * FROM " & Sh.name)
'-Set the name of the fields
Dim TheCells As range
Set TheCells = Sh.range("A2")
For i = 0 To rs.Fields.Count - 1
TheCells.Offset(0, i).Value = rs.Fields(i).name
'TheCells.Offset(1, i).Value = rs.Fields(i).Properties("Description").Value
Next i
答案 0 :(得分:1)
您可以使用ADOX获取列的属性。
Sub GetFieldDesc()
Dim axCat As ADOX.Catalog
Dim axTbl As ADOX.Table
Dim adCon As ADODB.Connection
Dim axProp As ADOX.Property
'Create an ado connection
Set adCon = New ADODB.Connection
adCon.Open sCON
'Point the adox catalog to that connection
Set axCat = New ADOX.Catalog
Set axCat.ActiveConnection = adCon
'Pick your table
Set axTbl = axCat.Tables("tblCurrentPriceDate")
Debug.Print axTbl.Columns(0).Properties("Description").Value
End Sub
设置对ActiveX Data Objects
和ADO Ext. x.x for DLL and Security
答案 1 :(得分:0)