使用VS2008报告向导和存储过程时报告为空
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过不使用向导解决了这个问题。
您可以使用报表查看器控件上的智能任务下可用的报表向导,而不是步骤 8 & 9 如果您想创建表格报告等。
I fixed this by not using the wizard.
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.
我记得不久前使用 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.