VB6 记录集和 SQL 计数

发布于 2024-12-25 06:30:39 字数 998 浏览 0 评论 0原文

我注意到,当我开始运行下面的程序时,数据库表中的记录数量(从日期表中选择引用)突然增加,即使没有添加新记录。请注意,我通过在 SQL Studio Manager 中运行查询(即从日期表中选择引用)来确定行数会增加。当程序停止时;记录数量回落到原来的水平。这是代码。为什么会发生这种情况?尽管引用是唯一的,但表中没有主键。

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 

I am noticing that the number of records in a database table (select reference from datetable) suddenly increases when I start running the program below even though there are no new records added. Please note that I establish that the number of rows increases by running a query in SQL Studio Manager i.e. select reference from datetable. When the program stops; the number of records falls back to the original level. Here is the code. Why does this happen? There is no Primary Key in the table though Reference is unique.

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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So要识趣 2025-01-01 06:30:39

这有点令人困惑,但如果您指的是“intReadCount”给出的总数与表中的行数,那么看起来您似乎没有正确清除该值。在程序开始时,您可能希望在开始之前将“intReadCount”设置回 0,然后您应该会得到恒定的结果。

更新:见下面的评论

It's a little confused, but if you are referring to the total given by "intReadCount" against how many rows you have in the table then it looks as though you are not correctly clearing this value. At the beginning of the procedure you would want to set "intReadCount" back to 0 before starting, you should then get constant results.

Updated: See comments below

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文