如何使用 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 access 中的工作太多了.
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屋!
查看全文