使用 SQL Server Reporting Services 将数据集传递到子报表

发布于 2024-07-13 13:23:41 字数 425 浏览 8 评论 0原文

我正在使用 SQL Server Reporting Services 和 Visual Studio 附带的报表设计器。 我收到了一份非常大的报告。 它实际上太大了,以至于当我进行更改时,Visual Studio 会挂起(有时一次长达数小时)或崩溃。

我无能为力解决这个问题,所以我决定将报告的下半部分移到子报告中。 因此,我从一份巨大的、反应迟钝的报告开始,以两份小的、易于管理的报告结束——令人惊讶的是,这确实有效。

一个问题:我的子报告使用与主报告相同的数据。 现在,它通过重新查询数据库来填充其数据集。 与数据库的额外往返导致生成报告的时间增加一倍; 生成时间从 45 分钟缩短到 1 1/2 小时。

我想避免再次访问数据库,而是在两个报告中使用相同的数据集。

如何在报表和子报表之间共享或传递数据集?

I'm using SQL Server Reporting Services and the report designer that comes with Visual Studio. I've got a really big report. It's actually so large that Visual Studio hangs (sometimes for hours at a time) or just crashes when I make changes.

There is preciously little I can do to solve the problem, so I've decided to just move the bottom half of the report into a sub-report. So, I started with one enormous, unresponsive report and ended with two small, manageable reports -- surprisingly, this actually works.

One problem: my subreport uses the same data as my main report. Right now, it populates its dataset by re-querying the database. The extra round-trip to the database causes the report to take twice as long to generate; up from 45 minutes to 1 1/2 hours to generate.

I'd like to avoid hitting the database again, and instead use the same dataset in both reports.

How can I share or pass a dataset between a report and subreport?

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

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

发布评论

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

评论(6

音盲 2024-07-20 13:23:42

您可以使用虚拟参数来完成此操作:

i。 在主报告“MyData”中创建一个参数并勾选“内部”

ii。 将“MyData”的默认值设置为您的数据集

iii. 。 使用表达式设置子报告参数

=Parameters!MyData.Value

希望这有帮助,
邓肯

You can do it using a dummy parameter:

i. Create a parameter in your main report 'MyData' and tick 'internal'

ii. Set default value of 'MyData' to your data-set

iii. Set the sub-report parameter with the expression

=Parameters!MyData.Value

Hope this helps,
Duncan

木森分化 2024-07-20 13:23:42

如果创建表格,则可以合并详细信息行的所有单元格并将子报表作为内容。 然后将子报表的参数设置为要运行子报表的字段。

贾森

If you create a table, you can merge all the cells of the details row and put a subreport as the contents. Then set the parameter of the subreport to the field you want to run the subreport against.

Jason

太阳男子 2024-07-20 13:23:41

我认为这可以帮助你:
http://www.gotreportviewer.com/subreports/index.html

为子报表提供数据 - SubreportProcessing 事件 To
为您必须处理的子报表提供数据
子报表处理事件。 请注意,此事件位于 LocalReport 上
目的。 您可以添加这样的事件处理程序:

private void MainForm_Load(对象发送者,EventArgs e) 
  { 
      this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportEventHandler); 
  } 
  

下面是事件处理程序的示例。 在这个例子中
LoadSalesData 被定义为返回一个 DataTable。

void MySubreportEventHandler(对象发送者,SubreportProcessingEventArgs e) 
  { 
      e.DataSources.Add(new ReportDataSource("销售", LoadSalesData())); 
  } 
  

如果您的报告有多个子报告,您可以查看 ReportPath
SubreportProcessingEventArgs 的属性并为
相应的子报告。 您可能还想检查以下值
SubreportProcessingEventArgs 的Parameters属性并且仅返回
与子报表参数对应的数据子集,如
这里提到了。

I think this can help you:
http://www.gotreportviewer.com/subreports/index.html

Supplying data for the subreport - the SubreportProcessing event To
supply data for the subreport you have to handle the
SubreportProcessing event. Note that this event is on the LocalReport
object. You can add an event handler like this:

private void MainForm_Load(object sender, EventArgs e)
{
    this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportEventHandler);
}

Below is an example for the event handler. In this example
LoadSalesData is defined to return a DataTable.

void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
{
    e.DataSources.Add(new ReportDataSource("Sales", LoadSalesData()));
}

If your report has multiple subreports you can look at the ReportPath
property of SubreportProcessingEventArgs and supply data for the
corresponding subreport. You may also want to examine the values of
Parameters property of SubreportProcessingEventArgs and only return
the subset of data that corresponds to the subreport parameters, as
mentioned here.

掩耳倾听 2024-07-20 13:23:41

我很确定你不能。 您可能最好寻找完全重新设计报表的方法,使其不那么大......更不用说导出到 Excel 时子报表的各种问题了。

I'm pretty sure you can't. You're probably better off looking for ways to redesign the report entirely so that it's not so large... not to mention the various problems with subreports when exporting to excel.

生活了然无味 2024-07-20 13:23:41

我有几份报告称 SQL 非常复杂,当我尝试编辑它时,它会锁定 Visual Studio。 在这些报告中,我直接进入代码视图并直接编辑 XML,这很有效。 当 Visual Studio 神秘地使列比我设置的稍宽时,我也会这样做。 但是,我怀疑如果您对报告布局的编辑过多,您是否愿意走这条路。

是否可以使用两个报告都使用的存储过程来构建表,而不是在报告中运行查询? 第一个报告运行存储过程来构建表,然后两个报告只需查询该报告。 如果报表可由多个用户运行,请注意并发问题。

I have several reports that the SQL is so complex in that it locks up Visual Studio when I try to edit it. In these reports I go straight into the Code view and edit the XML directly, which works. I also do this when Visual Studio mysteriously makes columns slightly wider than I set them at. However, I doubt you'd want to go down this path if you are editing the layout of the report too much.

Instead of running your query in the report, would it be possible to build a table using a stored procedure that both reports use? The first report runs the stored procedure to build the table and then both reports simply query the report. Watch for concurrency problems if the report can be run by multiple users.

风流物 2024-07-20 13:23:41

您是否尝试过在列表中使用列表,其中两个列表使用相同的数据集,然后过滤内部列表以仅显示链接到外部列表的记录?

就执行时间而言,45 分钟一开始就显得很长。 我假设您已经对执行计划进行了一些分析,以验证您的查询或存储过程是否使用有意义的索引?

希望这有帮助,

比尔

Have you tried using a list within a list where both lists use the same dataset and then filter the inner list to display only records linked to the the outer list?

As far as the execution time, 45 minutes seems like an awful long time in the first place. I'm assuming you've done some analysis of the execution plan to verify your query or stored procedure is using meaningful indexes?

Hope this helps,

Bill

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