是否有将返回所有的列名在Microsoft Access表的查询?有的、Microsoft、Access

2023-09-06 23:36:49 作者:竹篱外的小黄花

我有一个,我连​​接到​​与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
 
精彩推荐
图片推荐