且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 SQL 在 Access 中列出表中的字段名称

更新时间:2023-02-18 23:19:09

我在 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.

这有帮助吗?