运行时填充的数据报告显示相同的记录而不是每个不同的记录

发布于 2024-11-01 15:10:38 字数 618 浏览 2 评论 0原文

我查询包含 5 条不同记录的 MySql 表。 然后我填写一份VB6数据报告。 我的表中有 5 条记录,其中包含“姓名”字段,问题是报告显示 5 个相同的名字而不是 5 个不同的名字。

这5个相同的名称都属于从数据库中获取的最后一条记录,下面是运行时填充数据报表标签的代码:

    Set rs = New ADODB.Recordset       'Creates record set
    strSQL = "select * from person"
     rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions

If rs.EOF Then
   GoTo ExitSub
Else
    For B = 1 To rs.RecordCount
   'MsgBox (rs!Name + " " + rs!Surname)
    rptRuntime.Sections("Section1").Controls("lblName").Caption = rs!Name
   rs.MoveNext
    Next B
End If
    rptRuntime.Show

正在填充的标签放置在详细信息部分,名为“Section1”。

I query a MySql table with 5 different records.
Then I fill a VB6 Data Report.
I have 5 records in the table with fields Name and Surname, problem is the report shows
5 same names instead of five different names.

The 5 same names all belong to the last record fetched from the database, here is the code to fill the Data Report label at runtime:

    Set rs = New ADODB.Recordset       'Creates record set
    strSQL = "select * from person"
     rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions

If rs.EOF Then
   GoTo ExitSub
Else
    For B = 1 To rs.RecordCount
   'MsgBox (rs!Name + " " + rs!Surname)
    rptRuntime.Sections("Section1").Controls("lblName").Caption = rs!Name
   rs.MoveNext
    Next B
End If
    rptRuntime.Show

The label that is being filled is placed in the Detail section, named "Section1".

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

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

发布评论

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

评论(2

猥︴琐丶欲为 2024-11-08 15:10:38

最好绑定到 Recordset 或自定义数据源对象。 DataReports 不需要过程代码。

Better to bind to the Recordset or a custom data source object. Procedural code isn't required with DataReports.

┈┾☆殇 2024-11-08 15:10:38

此代码块

For B = 1 To rs.RecordCount
'MsgBox (rs!Name + " " + rs!Surname)
rptRuntime.Sections("Section1").Controls("lblName").Caption = rs!Name
    rs.MoveNext
Next B

将连续设置 rs!Name 5 次,最后包含最后一次更改的 rptRuntime.Sections("Section1").Controls("lblName").Caption 。所有 5 个更改都发生在使用显示报告之前。

rptRuntime.Show

不用说,您将拥有一个具有固定标题的(重复报告)部分,在每次重复中显示相同的标题。

This block of code

For B = 1 To rs.RecordCount
'MsgBox (rs!Name + " " + rs!Surname)
rptRuntime.Sections("Section1").Controls("lblName").Caption = rs!Name
    rs.MoveNext
Next B

Is going to set rs!Name 5 times in a row, ending up with rptRuntime.Sections("Section1").Controls("lblName").Caption containing the last change. ALL 5 changes happened before the report is even displayed using

rptRuntime.Show

It goes without saying that you will have a (repeated report) section that has a fixed caption, showing the same caption in each repeat.

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