如何动态创建SSRS报告?

时间:2010-10-20 10:46:30

标签: c# reporting-services reporting service

我正在尝试在SSRS中创建报告。该报告为其数据调用存储过程。我想在表格中显示数据。 但事实是,存储过程的结果不时有所不同,因为每个客户都有自己的“模板”。这意味着客户A的结果可能是:

AccountNumber |的客户id
1234567890 0987654321
1579086421 1234565465
...................... ....................

对于客户B可能是:

客户名称 |的地址
客户B Teststreet 1
客户测试测试街2
...................... ....................

有50种不同的列可供选择。列的顺序也是可编辑的。我的存储过程负责这一点。我唯一想要的是将storedprocedure 1:1的结果集放在我的报告中(标题+正文)。你们知道怎么做吗?

如果那不可能,那么有没有C#解决方案?即在C#中创建报表对象,调整设置等。

由于

3 个答案:

答案 0 :(得分:4)

您可以根据存储过程返回的数据集动态创建SSRS报告。报告格式(RDL)已记录在案,其格式为XML格式。因此,您可以使用System.XML命名空间生成RDL。备用(和不支持)方式是引用RDL对象模型程序集(Microsoft.ReportingServices.RdlObjectModel) - 您可以在SSRS 2008服务器计算机上找到程序集并将其复制到本地计算机上。它提供了一个读取/生成RDL的对象模型。

我采用的方法是基于数据表动态生成RDL(作为XML),然后使用Web服务API在SSRS服务器上发布RDL。

答案 1 :(得分:1)

一种解决方案可能是修改您的SP,以便返回的数据类似于:

ColNameA       DataA       ColNameB    DataB
AccountNumber, 1234567890, CustomerID, 948477586
AccountNumber, 5466584426, CustomerID, 458852244

然后,在SSRS中拖出一张表。在ColNameA上创建一个组。在该组行中,将Field ColNameA放在第一列中,将ColNameB放在第二列中。

在Details Row中,将DataA放在第一列中,将DataB放在第二列中,它应如下所示:

alt text

我使用的示例查询是:

select 'AccountNumber' as ColNameA, 1234567890 as DataA, 'CustomerID' as ColNameB, 0987654321 as DataB UNION 
select 'AccountNumber' as ColNameA, 5546488393 as DataA, 'CustomerID' as ColNameB, 4747599393 as DataB

获取列的名称(AccountNumber,CustomerID或CustomerName,CustomerAddress)将是关键。你可以通过以下方式获得它们:

select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'my_table_name'

答案 2 :(得分:0)

您可以使用报表设计器提供的Rdlobjectmodel创建和更改报表。

您可以在项目中引用Microsoft.ReportingServices.Designer.Controls,但其中还包括所有依赖项(即20多个程序集),也可以在项目根目录级别的单独文件夹中复制以下DLL组,并用它来引用DLL

 Microsoft.ReportingServices.QueryDesigners
 Microsoft.ReportingServices.Designer.Controls
 Microsoft.ReportingServices.RdlObjectModel
 Microsoft.ReportingServices.ReportDesign.Common
 Microsoft.ReportingServices.RichText
 Microsoft.ReportingServices.RPLObjectModel


  private Report LoadReportTemplate()
  {
        const string docPath = "template.rdl";//path for your template report
        using (var fs = new FileStream(docPath, FileMode.Open))
        {
            var report = Report.Load(fs);
            return report;
        }
  }

关注Documentation的链接

相关问题