使用VS2008报告向导和存储过程时报告为空

发布于 2024-07-29 01:26:55 字数 469 浏览 4 评论 0原文

我正在使用 VS2008,编写一个 C# .NET 应用程序。 我有一个 SQL Server 2005 数据库服务器,其中的数据库包含多个存储过程。 我想在报告中显示存储过程数据。

因此,作为测试,我基于“报告 -> 报告应用程序”项目类型创建了一个全新的 VS2008 C# 项目。

我完成了向导,连接到数据库并从我想要使用的存储过程创建数据集。 我告诉报告向导创建一个表格报告,并且没有对列进行分组。

当我运行该应用程序时,报告查看器的顶部显示“报告 1”,但没有其他内容。 只有一页。

如果我按照完全相同的方法创建一个全新的应用程序,但这次从数据库中选择视图或表,我会得到一个包含数据的多页报告,正如您所期望的那样。

那么,为什么报告系统不使用存储过程,而是使用表或视图正常工作呢? 如果我在 SQL Management Studio 中执行该存储过程,它就可以工作,并且不需要任何参数。

I'm using VS2008, writing a C# .NET app. I have an SQL Server 2005 database server with a database which contains several stored procedures. I want to show the stored procedure data in a report.

So, as a test I created a brand new VS2008 C# project based on the "Reporting -> Reports Application" project type.

I went through the wizard, connecting to the database and creating the dataset from the stored procedure I wanted to use. I told the report wizard to create a tabular report and didn't bother grouping the columns.

When I ran the application, the report viewer appeared with "Report 1" in the top, but nothing else. There was only one page.

If I create a whole new application, following the exact same method, but this time choose either a View or a Table from my database, I get a multi-page report with data in it, as you'd expect.

So why isn't the reporting system working with stored procedures, but working fine with tables or views? The stored procedure works if I execute it in SQL Management Studio, and it needs no parameters.

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

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

发布评论

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

评论(2

九局 2024-08-05 01:26:55

我通过不使用向导解决了这个问题。

  1. 创建一个新的 WinForms 应用程序
  2. 通过右键单击解决方案资源管理器中的解决方案来手动添加数据集
  3. 通过双击解决方案资源管理器中的数据集 xsd 文件,然后右键单击空白区域并选择“添加-表”来手动添加 TableAdapter适配器...”
  4. 连接到数据库
  5. 选择“使用现有存储过程”
  6. 分配所需的存储过程并完成向导手动
  7. 将报告添加到解决方案
  8. 双击它,然后转到“数据->显示数据源”
  9. 拖动 将所需字段添加到报表中
  10. 将 Microsoft.Reporting.WinForms.ReportViewer 放入主窗体中
  11. 使用弹出的智能任务三角形来关联所需的报表

您可以使用报表查看器控件上的智能任务下可用的报表向导,而不是步骤 8 & 9 如果您想创建表格报告等。

I fixed this by not using the wizard.

  1. Create a new WinForms app
  2. Manually add a DataSet by right-clicking the solution in the Solution Explorer
  3. Manually add a TableAdapter by double-clicking on the DataSet xsd file in the Solution Explorer, then right-clicking the blank area and choosing "Add-Table Adapter..."
  4. Connect to the DB
  5. Choose "Use existing stored procedures"
  6. Assign the required stored procedure and complete the wizard
  7. Manually add a report to the solution
  8. Double-click it, then go to "Data->Show Data Sources"
  9. Drag the required fields onto the report
  10. Put a Microsoft.Reporting.WinForms.ReportViewer onto the main form
  11. Use the pop-out smart tasks triangle to associate the required report

You can use the report wizard available under the smart tasks thing on the reportviewer control instead of steps 8 & 9 if you want to create tabular reports, etc.

淡看悲欢离合 2024-08-05 01:26:55

我记得不久前使用 VS 2003 (Crystal Reports) 和 SQL Server 2000 时遇到一个问题,报表设计者无法确定存储过程返回的字段,结果生成了一个空白报表。 在本例中,原因是存储过程从 SP 中定义的表变量中选择其结果。

您检查过是否属于这种情况吗?

我可能已经把事情变得过于复杂了,也许原因更简单,但这是我看到你的帖子时立即想到的场景。

当时我的问题的解决方案是创建一种“包装器”SP,并在表值函数中执行所有计算。 然后 SP 从该函数中选择数据 (SELECT a, b, c FROM dbo.MyFunc(@param)),这使得报表设计者能够检索字段列表。 我需要 SP,因为设计器不支持参数化 SELECT 查询。 不过,此解决方法是在小型应用程序中实现的,我不确定此方法如何或是否会影响更大规模的性能。

I remember having an issue a while back using VS 2003 (Crystal Reports) and SQL Server 2000, where the report designer was unable to determine the fields returned by the stored procedure, and as a result generated a blank report. In this case the reason was that the stored procedure selected its results from a table variable defined in the SP.

Have you checked if this is the case?

I might be over-complicating things already, maybe the reason is much more straight-forward, but this was the scenario that immediately came to mind when I saw your post.

The solution to my problem back then was to create a sort of 'wrapper' SP instead, and perform all calculations in a table-valued function. The SP then selected data from this function (SELECT a, b, c FROM dbo.MyFunc(@param)), which enabled the report designer to retrieve the list of fields. I needed the SP since the designer didn't support parameterized SELECT-queries. This workaround was implemented in a small application though, and I'm not sure how or if this approach affects performance on a larger scale.

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