如何将数据从二进制CSV文件复制到本地Access数据库而不保存计算机上的文件?

时间:2014-11-05 23:24:53

标签: sql vba csv access-vba

我是ADODB对象的新手。不确定这是否可行,但应该可以,我有一个中等大小的csv文件,我想从URL自动下载,然后上传到选定的本地访问数据库。

我可以将CSV数据存储在ADODB.Stream对象中,但是如何将其上传到本地访问数据库,创建新表并插入数据并分隔数据?

到目前为止我的代码

Dim HTTPReq As XMLHTTP60: Set HTTPReq = New XMLHTTP60

Dim ADOBStream As ADODB.Stream: Set ADOBStream = New ADODB.Stream

Temp = http://ichart.finance.yahoo.com/table.csv?s=ALFA.ST&a=4&b=24&c=2010&d=9&e=27&f=2013&g=d&ignore=.csv`

HTTPReq.Open "Get", temp, False
HTTPReq.send

Do Until HTTPReq.readyState = 4
    DoEvents
    Loop

Dim SplitTicker() As String: SplitTicker = Split(stock, ".") ' Splits the ticker name
Dim xPath As String: xPath = "C:\**Path***" & SplitTicker(0) & Date & ".csv"


' Import directly to Access Database which then delimits and adds primary keys to the data
' No need to save the File on the computer in this case
With ADOBStream
    .Open
    .Type = adTypeBinary
    .Write HTTPReq.responseBody
    .SaveToFile (xPath)   ' make an error handling where specified C:\ generates error
    .Close
    End With

Set HTTPReq = Nothing
Set ADOBStream = Nothing

0 个答案:

没有答案