VB6 加速 Microsoft Access 資料庫中的資料庫作業速度

引用自Microsoft:http://support.microsoft.com/kb/146908/zh-tw

重點:
如果您沒有使用 BeginTrans 與 CommitTrans 陳述式,在 486/66 的電腦上,此程式會向您報告新增 100 筆記錄的時間是 17 秒。
當您依上面程式註解所示,加入 BeginTrans 與 CommitTrans 時,程式在同一部電腦上只花了不到 1 秒的時間。執行效能在不同的電腦上可能會有差異。

         'BeginTrans  ' Add this and CommitTrans (below) for greater speed.
         For i = 1 To 100
            tempName = "testname" & Str$(i) ' Make an arbitrary unique
                                            '  string.
            tempPhone = Str$(i)             ' Make arbitrary number.
            t.AddNew ' AddNew clears copy buffer to prepare for new record.
            t!PubID = 30 + i  ' Set primary key to unique value.
            t!Name = tempName  ' Set Name field to unique value.
            t!Telephone = tempPhone  ' Set Telephone field to unique value.
            t.Update   ' Write the record to disk or to transaction buffer.
         Next i
         'CommitTrans  ' Add this and BeginTrans (above) for greater speed.


留言