我正在尝试使用 jet SQL 查询从表中读取列名。数据表以 2002-2003 兼容模式保存在 ms-access 中。我已经为查询尝试了几种变体,但似乎无法获得正确的语法。
DatabaseConnection("SELECT Column_name" & " FROM " & tablename, "Read Recordset")
DatabaseConnection("select column_name from information_schema.columns where table_name = tabDataHourly", "read Recordset")
我有一个运行数据库连接的函数: 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
任何帮助将不胜感激。