用于查询 CSV 文件的 ADO 连接字符串 - "Not a Valid Path.." 错误
ADO Connection String to query a CSV File - "Not a Valid Path.." Error
我似乎无法弄清楚我的连接字符串有什么问题。我要查询 Excel.CSV 文件。
Sub test()
Dim myConn As New ADODB.Connection
Dim recSet As New ADODB.Recordset
Dim myPath As String
Dim connStrng As String
Dim qryStrng As String
Dim ReiterName As String
myPath = "C:\Users\FirstName.LastName\Desktop\temp.csv"
connStrng = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & myPath & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
Debug.Print connStrng
myConn.Open connStrng <-- 'C:\Users\FirstName.LastName\Desktop\temp.csv' Not a valid path error
完整代码供参考
Sub test()
Dim myConn As New ADODB.Connection
Dim recSet As New ADODB.Recordset
Dim myPath As String
Dim connStrng As String
Dim qryStrng As String
Dim ReiterName As String
myPath = "C:\Users\FirstName.LastName\Desktop\"
connStrng = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & myPath & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
Debug.Print connStrng
myConn.Open connStrng
recSet .Open "SELECT * FROM temp.csv", myConn
runSQLQueryForCSV = RecSet.GetRows()
myConn.Close
Set recSet = Nothing
Set myConn = Nothing
End Function
我似乎无法弄清楚我的连接字符串有什么问题。我要查询 Excel.CSV 文件。
Sub test()
Dim myConn As New ADODB.Connection
Dim recSet As New ADODB.Recordset
Dim myPath As String
Dim connStrng As String
Dim qryStrng As String
Dim ReiterName As String
myPath = "C:\Users\FirstName.LastName\Desktop\temp.csv"
connStrng = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & myPath & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
Debug.Print connStrng
myConn.Open connStrng <-- 'C:\Users\FirstName.LastName\Desktop\temp.csv' Not a valid path error
完整代码供参考
Sub test()
Dim myConn As New ADODB.Connection
Dim recSet As New ADODB.Recordset
Dim myPath As String
Dim connStrng As String
Dim qryStrng As String
Dim ReiterName As String
myPath = "C:\Users\FirstName.LastName\Desktop\"
connStrng = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & myPath & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
Debug.Print connStrng
myConn.Open connStrng
recSet .Open "SELECT * FROM temp.csv", myConn
runSQLQueryForCSV = RecSet.GetRows()
myConn.Close
Set recSet = Nothing
Set myConn = Nothing
End Function