1
這是我的代碼,但它將大約一個小時將所有1700萬行導出到mdb中。我無法爲此使用mysql或sql server。我必須在訪問數據庫中執行此操作,並快速將此過程在一週內運行一次。 Plz建議可用於此任務的最快方法使用ADO將大型csv文件導入到mdb時的性能問題
Sub insertDataIntoMDB()
Dim Dbfilepath As String
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set rst = CreateObject("ADODB.Recordset")
Dim arrData() As String
Dim s As String
Dim i As Integer
Dbfilepath = ThisWorkbook.Path & "\DB\Interface.accdb"
cnn.Open "Provider= Microsoft.ACE.OLEDB.12.0;" & " Data Source=" & Dbfilepath & ";" & "Persist Security Info =False;"
q1 = "DELETE * FROM MYTABLE"
Set rs = cnn.Execute(q1)
'q1 = "ALTER TABLE MyTable ALTER COLUMN ID autonumber(1,1)"
'Set rs = cnn.Execute(q1)
p = UserForm1.csvFolder & "\" & sItem & ".csv"
Open p For Input As #1
Do While Not EOF(1)
Close #1
Line Input #1, s
arrData = Split(s, ",")
q1 = "INSERT INTO MyTable(F1,F2,F3) values(" & arrData(0) & "," & arrData(1) & "," & arrData(2) & ")"
Set rst = cnn.Execute(q1)
Loop
Close #1
rs.Close
rs`enter code here`t.Close
Set rst = Nothing
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
請詳細介紹一下所有使用表格(MYTABLE)和CSV文件的情況,它們的外觀如何? (結構,數據)等。 –
你爲什麼希望使用MS Access?例如。 DoCmd.TransferText? – user1917229