我正在尝试使用CSV文件中的数据更新数据库。我有这么远,但我不知道从哪里开始:
Dim web As String
web = "http://download.finance.yahoo.com/d/quotes.csv?s=" & Symbol & "&f=a"
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(web)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim sourcecode As String = sr.ReadToEnd()
' Database connection
Dim daoengine As DAO.DBEngine
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
daoengine = New DAO.DBEngine
dbs = daoengine.OpenDatabase("Project.mdb")
答案 0 :(得分:0)
您可以对数据库执行sql。以下是VBA的一些注释:
scn = "[Text;FMT=Delimited;HDR=Yes;DATABASE=Z:\Docs]"
''Example for simply importing from the CSV
ssql = "SELECT * INTO TestTable FROM " & scn & ".[Test.CSV] "
''Example for updating an existing table
ssql = "INSERT INTO TestTable SELECT * FROM " & scn & ".[Test.CSV] " _
& "WHERE ID Not In (SELECT ID FROM TestTable)"
''dao.dbFailOnError = 128
dbs.Execute ssql, dbFailOnError