Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何动态创建SSRS报告?_C#_Reporting Services_Reporting_Service - Fatal编程技术网

C# 如何动态创建SSRS报告?

C# 如何动态创建SSRS报告?,c#,reporting-services,reporting,service,C#,Reporting Services,Reporting,Service,我正在尝试在SSRS中创建一个报告。报表为其数据调用存储过程。我想在表格中显示数据。 但问题是,存储过程的结果有时不同,因为每个客户都有自己的“模板”。这意味着客户A的结果可能是: 账号|客户ID 1234567890 0987654321 1579086421 1234565465 ...................... .................... 对于客户B而言,可以是: 客户名称|地址 客户B Teststreet 1 客户测试街2 ..................

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

账号|客户ID
1234567890 0987654321
1579086421 1234565465
...................... ....................

对于客户B而言,可以是:

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

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

如果不可能的话,有没有解决办法?例如,在C#中创建报告对象、调整设置等


谢谢

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


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

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


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

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

ColNameA       DataA       ColNameB    DataB
AccountNumber, 1234567890, CustomerID, 948477586
AccountNumber, 5466584426, CustomerID, 458852244
然后,在SSR中拖出一张表。在ColNameA上创建一个组。在该组行中,将字段ColNameA放在第一列中,将ColNameB放在第二列中

在“详细信息”行中,将DataA放在第一列,将DataB放在第二列,如下所示:

我使用的示例查询是:

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'

一种解决方案可能是修改SP,使返回的数据看起来像:

ColNameA       DataA       ColNameB    DataB
AccountNumber, 1234567890, CustomerID, 948477586
AccountNumber, 5466584426, CustomerID, 458852244
然后,在SSR中拖出一张表。在ColNameA上创建一个组。在该组行中,将字段ColNameA放在第一列中,将ColNameB放在第二列中

在“详细信息”行中,将DataA放在第一列,将DataB放在第二列,如下所示:

我使用的示例查询是:

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'

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

按照

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

按照

的链接,如何基于存储过程返回的数据集创建动态报告?你能解释一下怎么做吗?通过reportdesigner?生成RDL文件并不是一个真正的解决方案,因为100+ppl与应该生成RDL文件的webapp同时工作,这意味着100+(每天)RDL文件将保存在服务器上。。还是我搞错了?如前所述,您需要为RDL文件生成xml。例如,在designer中创建一个示例列报告,并在文本编辑器中打开RDL。通过这种方式,您将了解如何在RDL文件中映射报表列和字段。现在,基于数据集中的列,您需要生成一个RDL文件。在我们的例子中,我们确实生成了RDL文件,但没有在SSRS服务器上发布它们——而是在本地模式下使用ReportViewer控件来显示它们。生成的RDL文件是在临时目录中创建的,并定期清理。继续,生成的RDL文件数量将根据使用情况而定。例如,如果您只能有一定数量的组合,那么您可以生成这些RDL作为模板,并在需要时使用它们。如果这不可行,那么您必须为每个可能的列(和顺序)组合生成RDL。我编写了一个C#应用程序,它动态生成RDL文件,并用ReportViewerMaxiBlue加载它——我和你在同一条船上。我已经通过XML动态生成了RDL文件。你能给我举一些例子说明你是如何用reportviewer在本地模式下加载它的吗?谢谢,如何基于从返回的数据集创建动态报告