如何在使用SQL的Access中的表中列出字段名称 [英] How to List Field's Name in table in Access Using SQL
本文介绍了如何在使用SQL的Access中的表中列出字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
能否让我知道是否可以在MS Access表中列出所有字段名称?
Can you please let me know if it is possible to list all fields name in a MS Access table?
推荐答案
我在ms访问中工作太多.
I work in ms access far too much.
我唯一知道的方法是使用vba,并定义一个记录集,然后遍历字段.
The only way I know of to do this, would be using vba, and defining for example a recordset, and looping through the fields.
例如:
Sub ListFields()
dim rst as new adodb.recordset
rst.open "SELECT * FROM SomeTable", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
' Note: adOpenForwardOnly and adLockReadOnly are the default values '
' for the CursorType and LockType arguments, so they are optional here '
' and are shown only for completeness '
dim ii as integer
dim ss as string
for ii = 0 to rst.fields.count - 1
ss = ss & "," & rst.fields(ii).name
next ii
Debug.Print ss
End Sub
字符串变量ss
将包含一个用逗号分隔的列表,该列表包含名为"SomeTable"的表中所有列的名称.
The string variable ss
will contain a comma-delimited list of all the column names in the table named "SomeTable".
通过稍微重新格式化逻辑,您应该可以将数据插入到另一个表中,然后查询出来.
With a little reformatting of the logic you should be able to insert this data into another table if you wanted to, then query it out.
有帮助吗?
这篇关于如何在使用SQL的Access中的表中列出字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文