VB6记录集更新 [英] VB6 Recordset update
问题描述
我正在运行一个vb6程序,该程序正在数据库表中的许多记录之间循环,并在字段中输入日期。这将需要很多小时才能运行。
I am running a vb6 program that is looping through many records in a database table and entering a date into a field. This will take many hours to run.
我注意到表中的记录数每几秒钟增加1,然后减少1(返回到原始计数)。
I am noticing that the number of records in the table is increasing by 1 every few seconds and then reducing by 1 (going back to the original count). Is there a reason for this?
我正在使用VB6记录集和更新功能(即rs.update)。我没有插入任何新记录。
I am using a VB6 recordset and the update function i.e. rs.update. I am not inserting any new records.
代码如下:
rs.Open "select reference,value1,datefield from datetable where field1 = 'value1' " & _
"order by reference", objAuditCon.ActiveCon, adOpenStatic, adLockPessimistic
Do While Not rs.EOF
intReadCount = intReadCount + 1
DoEvents
If Not IsNull(rs("value1")) Then
testArray = Split(rs("value1"), ",")
rs2.Open "SELECT Date FROM TBL_TestTable WHERE Record_URN = '" & testArray(1) & "'", objSystemCon.ActiveCon, adOpenStatic, adLockReadOnly
If rs2.EOF Then
End If
If Not rs2.EOF Then
rs("DateField") = Format$(rs2("Date"), "dd mmm yy h:mm:ss")
rs.Update
intWriteCount = intWriteCount + 1
End If
rs2.Close
Else
End If
rs.MoveNext
Loop
rs.Close
推荐答案
简单答案:取出DoEvents语句。如果您使用它来刷新屏幕,则在进行1000次循环迭代后,定期对GUI进行手动刷新。
Simple answer: take out the DoEvents statement. If you are using it to get screen refresh, the periodically do a manual refresh of your GUI after, say, 1000 iterations of the loop.
原因可能是引起问题的是,调用DoEvents时可能正在执行的其他代码可能无法控制。
The reason why this may be causing an issue is that other code you may have no control over might be being executed when you call DoEvents.
这篇关于VB6记录集更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!