现在,我正在遍历 Excel 电子表格中的每一行,并使用插入查询将每一行插入到我的 Access 表中。它有效,但速度很慢。如何进行一次查询以一次添加所有记录?
这是我当前的代码
Sub Insert()
Dim rs As ADODB.Recordset, strSQL As String, minPrem As Double, i As Long, datetime As Date
datetime = Now()
Call DB.ConnectToDB 'Connect to the database
Set rs = New ADODB.Recordset
i = 7 'first row of data
Do While (Cells(i, 1) <> "")
If (IsNumeric(Cells(i, 6))) Then
minPrem = Cells(i, 6)
Else
minPrem = 0
End If
strSQL = "INSERT INTO Rates (EffectiveDate, State, Company, ClassCode, Rate, MinPremium, TimeOfEntry) VALUES " _
& "(#" & Cells(i, 1) & "#,'" & Cells(i, 2) & "','" & Cells(i, 3) & "','" & Cells(i, 4).Text & "'," & Cells(i, 5) & "," & minPrem & ", #" & datetime & "#)"
rs.Open strSQL, Cn
i = i + 1
Loop
End Sub