大家,帮我看看~~~~~~~
以下是我的代码:adoRS.EOF 这句第二次执行时很慢
On Error GoTo ErrHandle:
Set conn = Nothing
conn.ConnectionString = constr
conn.Open
conn.BeginTrans '开启事务
Dim j As Integer
j = 0
For i = 1 To fg1.Rows - 1
Call closeconn
Call openconn
Call rs("select jcxm from tbfz where jcxm='" & Trim(fg1.TextMatrix(i, 1)) & "'")
If adoRS.EOF Then '第一次到这句很快的,第二次到这句就慢了。要等很久
adoRS.Close
conn.Execute "insert into tbfz(jcxm,fenzhi) values('" & Trim(fg1.TextMatrix(i, 1)) & "','" & Trim(fg1.TextMatrix(i, 2)) & "')"
j = j + 1
End If
Next
conn.CommitTrans '提交事务
MsgBox "导入成功,共导入 " & j & " 条信息"
Command4_Click
conn.Close
Set conn = Nothing
Exit Sub
'错误处理
ErrHandle:
conn.RollbackTrans '出错,回滚事务
conn.Close
MsgBox "导入失败,错误原因为:" & Err.Description, vbExclamation, "提示"
' conn.Close
Exit Sub
以下是rs方法:
Public Sub rs(ByVal sqlstr As String)
On Error GoTo checkerr2
adoRS.Open sqlstr, adoCon, adOpenDynamic, adLockOptimistic
Exit Sub
checkerr2:
MsgBox "有误"
Call closeconn
'End
End Sub
[解决办法]
首先不说你语句问题,你应该用insert()(select ... from ..where)加条件的批量插入语句才对。