I am trying to read the column names from a table using a jet SQL query. The data table is held in ms-access in 2002-2003 compatibility mode. I have tried a couple of variations for the query but I can’t seem to get the correct syntax.
DatabaseConnection("SELECT Column_name" & " FROM " & tablename, "Read Recordset")
DatabaseConnection("select column_name from information_schema.columns where table_name = tabDataHourly", "read Recordset")
I have a function that runs the database connections:
Public Function DatabaseConnection(ByVal Query As String, ByVal Task As String) As String
‘On Error GoTo Err
cnnOLEDB = New OleDbConnection
cnnOLEDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataDirectoryName & DatabaseFileName
cnnOLEDB.Open()
cmdOLEDB.Connection = cnnOLEDB
cmdOLEDB.CommandText = Query
Select Case Task
Case "Read Recordset"
rdrOLEDB = cmdOLEDB.ExecuteReader()
DatabaseConnection = "Read Recordset"
Case "Read Scalar"
DatabaseConnection = cmdOLEDB.ExecuteScalar
Case "Non-Query"
cmdOLEDB.ExecuteNonQuery()
DatabaseConnection = "Non-Query"
End Select
Exit Function
Err:
MsgBox("Database connection error.")
DatabaseConnection = "Error"
End Function
Any help would be greatly appreciated.
Some notes on getting a field (column) name: