我正在尝试从ADODB中读取.csv。这是我正在尝试的.csv的直接复制和粘贴:
Application Number,Received Date
V222333444,2019-05-05
S222333444,2019-05-05
W222333444,2019-05-05
如果我选择SQL中的所有列,那么它似乎可以工作:
SELECT * FROM `New Data - Rec'd Date.csv`
但是,如果我指定了某些列(最终将要做):
SELECT [Application Number] FROM `New Data - Rec'd Date.csv`
然后,我似乎可以选择任何列,除了,第一个列。尝试执行SQL时,出现运行时错误“没有为一个或多个必需参数提供值”。
我尝试过切换列的顺序并为.csv加上别名,但均无济于事。
我觉得.csv的格式可能有问题,但是我最初是通过在Excel中输入数据并保存来创建它的,所以不应该这样。 Excel现在打开它没有问题。熊猫也没有:
import pandas as pd
csv_path = r"C:\Users\User\Google Drive\8 - Coding\1 - VBA work\VAC Appointment Booking\Data\New Data - Rec'd Date.csv"
df = pd.read_csv(csv_path)
我可能必须为ADODB创建架构,如果是的话,最简单的方法是什么?还有吗预先谢谢你。
我的完整VBA如下:
Public Function accessCSV(ByVal strCSVPath As String, _
ByVal strMasterData As String, _
ByVal strNewMainData, _
ByVal strNewEmailData) As ADODB.Recordset
Application.StatusBar = "Accessing CSVs..."
Dim strCon As String, strSQL As String
Dim oConnection As New ADODB.Connection
Dim oTempRecordSet As ADODB.Recordset
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strCSVPath & ";" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited"";"
oConnection.Open strCon
strSQL = "SELECT [Application Number] FROM `New Data - Rec'd Date.csv`"
'The line that causes the error
Set accessCSV = oConnection.Execute(strSQL)
Set oConnection = Nothing
Application.StatusBar = False
End Function