我正在尝试从VB6连接到Access数据库2013(.accdb),并不断出错。我的代码如下:
Dim db_file As String
Dim statement As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
' Get the data.
db_file = App.Path
If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
db_file = db_file & "FluidFlo.accdb"
' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & db_file & ";" & "Persist Security Info=False"
conn.Open '(PROBLEM IS HERE)
' Select the data.
statement = "SELECT strEmpName FROM tblEmployees ORDER BY strEmpName"
' Get the records.
Set rs = conn.Execute(statement, , adCmdText)
' Load the results into the ComboBox
Do Until rs.EOF
cboUsername.AddItem rs!strEmpName
rs.MoveNext
Loop
' Close the recordset and connection.
rs.Close
conn.Close
我试图将表加载到程序的组合框中,并假设我的连接字符串有错误。我将Provider=Microsoft.ACE.OLEDB.12.0;
更改为Provider=Microsoft.ACE.OLEDB.15.0;
,但还是没有运气。不断出现错误。
是否有人知道如何连接到.accdb数据库,无论是SQL命令还是其他命令?在此先感谢...(拉出我的头发...)