1

我有一个 SQL Reporting Services 报告(使用 Report Builder v2.0 构建的 SQL 2008),它有一个多选整数参数(在本例中为商店列表)。

默认值为0(“所有商店”)。参数作为varchar(1024).

这一切都可以在报表生成器或 Reporting Services 网站上正常工作。

但是,在使用该组件的 ASP.NET 网站上ReportViewer,每次选择“查看报告”时,参数都会重置为默认值。

我尝试将视图设置为非异步加载(更改渲染容器?)加上我能找到的任何其他设置,但没有成功。有谁知道解决这个问题的技巧?

4

3 回答 3

2

我犯了一个错误。该ReportViewer控件位于母版页内。每次单击“查看报告”按钮时,它都会进行回发并重置会话。

if (!IsPostBack)在报告设置方法之前添加了。

于 2009-03-31T21:56:11.610 回答
1

我发现与原始海报类似的代码错误。每次加载页面时,我都会(重新)设置报表服务器凭据,而不仅仅是在初始化时。显然,设置报告凭据会重置所有参数。

于 2009-06-02T17:01:19.583 回答
1

For those of you who experience this error for reasons not listed by the original poster...

Here is a similar scenario.

You have a report which uses a multi-select report parameter. This parameter is populated by a datasource, which bases its values off some table query.

When you use the 'Select All' option for this report parameter and press the 'View Report' button, the parameter is reset to blank and your report is not generated.

I believe this problem occurs because something invalidates your dataset while the query is being performed, but I cannot be 100% certain.

What I do know, is that by using a table variable as the dataset's query source, you make this problem go away.

For example, your CityDataSource could be populated by the query:

SELECT DISTINCT city, city as SortOrder from accounts
UNION
SELECT 'All' as city, '0' as SortOrder
ORDER BY SortOrder

If you've been making SQL Reporting Services reports, you may have stumbled upon this solution once or twice.

Now, we change the CityDataSource query to look like the following:

DECLARE @citytable TABLE (city varchar(255), sortorder varchar(255))
INSERT INTO @citytable (city, sortorder) VALUES
(
SELECT DISTINCT city, city as SortOrder from accounts
)
SELECT city, sortorder FROM @citytable ORDER BY sortorder

And by doing that your report's parameters won't reset anymore.

A stored procedure would also work, I suspect.

于 2009-04-02T18:05:36.123 回答