You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSRS Report Viewer API:MDX数据源字段表达式返回空值问题

问题:SSRS ReportViewer加载本地RDL报表显示空值,SSAS查询在设计器预览正常

我正在使用SSRS ReportViewer控件显示本地RDL报告,该报告的共享数据源指向SSAS立方体。通过Microsoft.Reporting.Webforms API将MDX数据源添加至LocalReport对象,数据源查询正常并已分配给报告对象,代码如下:

var adapter = new AdomdDataAdapter();
var queryCmd = connection.CreateCommand();

adapter.SelectCommand = queryCmd;
RdlQuery rdlQuery = rdlDataSet.Query;
queryCmd.CommandText = rdlQuery.CommandText;

var adoNetDataSet = new DataSet();

using (connection)
{
    connection.Open();
    var schemaDs = new DataSet();
    adapter.FillSchema(schemaDs, SchemaType.Source);

    var mapping = new DataTableMapping
    {
        DataSetTable = "Table",
        SourceTable = schemaDs.Tables[0].TableName
    };

    foreach (RdlField field in rdlDataSet.Fields)
        mapping.ColumnMappings.Add(field.DataField, field.Name);

    adapter.TableMappings.Add(mapping);
    adapter.Fill(adoNetDataSet);
}

var reportDs = new rs.ReportDataSource(rdlDataSet.Name, adoNetDataSet.Tables[0]);
localReport.DataSources.Add(reportDs);

问题现象

运行后Report Viewer控件中返回空值,但相同查询在Visual Studio报表设计器预览中正常显示。

补充信息

  • 报表DataSet的SSAS查询语句:
SELECT [Measures].[CurrentAmount] as CurrentAmount ON COLUMNS,
    STRTOMEMBER("[Year].[version].[" + @Param1 + "]") ON ROWS
FROM [Model]
  • 字段配置:
Name: CurrentAmount
Field Source: <?xml version="1.0" encoding="utf-8"?><Field xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Measure" UniqueName="[Measures].[CurrentAmount]" />
  • 报表中展示数据的字段表达式:
=First(Fields!CurrentAmount.Value, "DataSet1")

我推测问题可能与列映射有关,调试时发现DataTable的列名为[Measures].[CurrentAmount],与字段表达式中的CurrentAmount不一致,调试修改列名后仍未解决。

内容的提问来源于stack exchange,提问作者user3167162

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 00:45:14