开发者

Is there a query that will return all of the column names in a Microsoft Access table?

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.

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

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = 'TableName' 
开发者_Go百科

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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜