MS Access: Why is ADODB.Recordset.BatchUpdate so much slower than Application.ImportXML?

后端 未结 1 1606
花落未央
花落未央 2020-12-10 18:34

I\'m trying to run the code below to insert a whole lot of records (from a file with a weird file format) into my Access 2003 database from VBA. After many, many experiment

相关标签:
1条回答
  • 2020-12-10 19:26

    Unless you must do this with ADO, try DAO instead. Here are the times on my laptop with your procedure and a DAO version:

    ADO:
    starting loop 9:51:59 PM
    done loop     9:52:00 PM
    done update   9:52:54 PM
    
    DAO:
    starting loop 9:58:29 PM
    done loop     9:58:31 PM
    done update   9:58:31 PM
    

    This is the DAO version I used.

    Sub TestBatchUpdateDAO()
    
        CurrentDb.Execute "create table testy (x int, y int)"
    
        Dim rs As DAO.Recordset
        Set rs = CurrentDb.OpenRecordset("testy", dbOpenTable, dbAppendOnly)
        Dim i As Long
    
        Debug.Print "starting loop", Time
        For i = 1 To 10000
            rs.AddNew
            rs!x = 50
            rs!y = 55
            rs.Update
        Next i
        Debug.Print "done loop", Time
    
        'rs.UpdateBatch '
        Debug.Print "done update", Time
    
        rs.Close
        Set rs = Nothing
        CurrentDb.Execute "drop table testy"
    End Sub
    
    0 讨论(0)
提交回复
热议问题