是否有将返回所有的列名在Microsoft Access表的查询? [英] Is there a query that will return all of the column names in a Microsoft Access table?

查看:387
本文介绍了是否有将返回所有的列名在Microsoft Access表的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个,我连​​接到​​与Jet数据库引擎,使用VB.NET Microsoft Access数据库。我希望以编程方式获取所有的列名的特定表。

I have a Microsoft Access database that I connect to with the Jet Database Engine, using VB.NET. I want to programmatically get all of the column names for a particular table.

我想做到这一点的MS SQL语句相当于:

I would like to do the equivalent of this MS SQL statement:

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = 'TableName' 

这是可能的访问?如果不是,我有哪些选择获取的列名?

Is this possible in Access? If not, what are my options for getting the column names?

推荐答案

我找到了一种方法使用的在.NET连接类的getSchema 方法。

I found a way to do this using the GetSchema method of the .NET Connection class.

我写了一个返回列名特定表的方法。

I wrote a method that returns column names for a particular table.

Private Function GetColumnNamesInTable(ByVal connectionString As String, ByVal tableName As String) As List(Of String)
    Dim connection As OleDbConnection = New OleDbConnection(connectionString)
    Dim restrictions As String() = New String() {Nothing, Nothing, tableName, Nothing}
    connection.Open()
    Dim dataTable As DataTable = connection.GetSchema("Columns", restrictions)
    connection.Close()
    Dim returnList As List(Of String) = New List(Of String)
    For Each dataRow As DataRow In dataTable.Rows
        returnList.Add(dataRow("Column_Name"))
    Next
    Return returnList
End Function

这篇关于是否有将返回所有的列名在Microsoft Access表的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆