如何动态创建 SSRS 报告?

发布于 2024-09-28 06:18:46 字数 805 浏览 2 评论 0原文

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

AccountNumber | 客户ID
1234567890         0987654321
1579086421         1234565465
......................        ...................

对于客户 B 可以是:

CustomerName | 地址
客户B        测试街 1
客户测试    测试街2
......................     ...................

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

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

谢谢

Im trying to create a report in SSRS. The report calls a stored procedure for its data. I want to display the data in a table.
But the thing is, the result from the stored procedure differs from time to time, because every customer has its own 'template'. This means the result for customer A could be :

AccountNumber | CustomerID
1234567890           0987654321
1579086421           1234565465
......................          ....................

and for customer B could be:

CustomerName | Address
Customer B          Teststreet 1
Customer Test     Teststreet 2
......................      ....................

There are 50 different columns to choose from. The order of the columns is also editable. My stored procedure takes care of this. The only thing I want is to put the resultset of the storedprocedure 1:1 in my report (header+body). Do you guys know how to do this?

If thats not possible, is there a C# solution to this? I.e creating a report object in C#, adjust settings etc.

Thanks

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

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

发布评论

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

评论(3

感性不性感 2024-10-05 06:18:46

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

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

You can create the SSRS report dynamically based on the data set returned by the stored procedure. The report format (RDL) is documented and its an XML format. So you can use System.XML namespace to generate RDL. Alternate (and unsupported) way is to refer RDL object model assembly (Microsoft.ReportingServices.RdlObjectModel) - you can locate the assembly on SSRS 2008 server machine and copy it on your local machine. It offers an object model to read/generate RDL.

I have adopted approach where RDL is generated (as XML) dynamically based on the data-table and then publish the RDL on SSRS server using web services API.

有木有妳兜一样 2024-10-05 06:18:46

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

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

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

在详细信息行中,将 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'

One solution might be to modify your SP so that the data returned looks something like:

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

Then, in SSRS drag out a table. Create a group on ColNameA. In that Group Row, place the Field ColNameA in the first Column, place ColNameB in the second column.

In the Details Row, place DataA in the first column, and DataB in the second column, and should look like this:

alt text

The sample query i used was:

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

Getting the names of the Columns (AccountNumber, CustomerID or CustomerName, CustomerAddress) will be the key. You can get them via:

select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'my_table_name'
海的爱人是光 2024-10-05 06:18:46

您可以使用报表设计器提供的 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;
        }
  }

请点击 文档的链接

You can use the Rdlobjectmodel provided by the Report designer to create and alter a report.

You can reference the Microsoft.ReportingServices.Designer.Controls in to your project but that includes all the dependencies as well which is 20+ assembly or you can copy the following set of DLLs in a separate folder at your project root level and use it to reference the DLLs

 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;
        }
  }

Follow the link for Documentation

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