运行时填充的数据报告显示相同的记录而不是每个不同的记录
我查询包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好绑定到 Recordset 或自定义数据源对象。 DataReports 不需要过程代码。
Better to bind to the Recordset or a custom data source object. Procedural code isn't required with DataReports.
此代码块
将连续设置 rs!Name 5 次,最后包含最后一次更改的
rptRuntime.Sections("Section1").Controls("lblName").Caption
。所有 5 个更改都发生在使用显示报告之前。不用说,您将拥有一个具有固定标题的(重复报告)部分,在每次重复中显示相同的标题。
This block of code
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 usingIt goes without saying that you will have a (repeated report) section that has a fixed caption, showing the same caption in each repeat.