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.
我有一个Microsoft Access数据库,我使用VB.NET连接到Jet数据库引擎。我想以编程方式获取特定表的所有列名称。
I would like to do the equivalent of this MS SQL statement:
我想做相当于这个MS SQL语句:
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?
这在Access中是否可行?如果没有,我有什么选择获取列名?
1 个解决方案
#1
5
I found a way to do this using the GetSchema method of the .NET Connection class.
我找到了一种使用.NET Connection类的GetSchema方法执行此操作的方法。
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
#1
5
I found a way to do this using the GetSchema method of the .NET Connection class.
我找到了一种使用.NET Connection类的GetSchema方法执行此操作的方法。
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