第 3 课:从报表服务器加载报表定义
创建项目并从 RDL 架构生成类之后,您就可以从报表服务器加载报表定义了。
加载报表定义
如果对类使用 Visual Basic
Report
) ,请在类 (模块顶部ReportUpdater
添加私有字段。 此字段将用于在应用程序的生存期内维护对从报表服务器加载的报表的引用。private Report _report;
Private m_report As Report
将
LoadReportDefinition()
Program.cs 文件 (Module1.vb for Visual Basic) 中的 方法的代码替换为以下代码:private void LoadReportDefinition() { System.Console.WriteLine("Loading Report Definition"); string reportPath = "/AdventureWorks 2012 Sample Reports/Company Sales 2012"; // Retrieve the report definition // from the report server byte[] bytes = _reportService.GetItemDefinition(reportPath); if (bytes != null) { XmlSerializer serializer = new XmlSerializer(typeof(Report)); // Load the report bytes into a memory stream using (MemoryStream stream = new MemoryStream(bytes)) { // Deserialize the report stream to an // instance of the Report class _report = (Report)serializer.Deserialize(stream); } } }
Private Sub LoadReportDefinition() System.Console.WriteLine("Loading Report Definition") Dim reportPath As String = _ "/AdventureWorks 2012 Sample Reports/Company Sales 2012" 'Retrieve the report definition 'from the report server Dim bytes As Byte() = _ m_reportService.GetItemDefinition(reportPath) If Not (bytes Is Nothing) Then Dim serializer As XmlSerializer = _ New XmlSerializer(GetType(Report)) 'Load the report bytes into a memory stream Using stream As MemoryStream = New MemoryStream(bytes) 'Deserialize the report stream to an 'instance of the Report class m_report = CType(serializer.Deserialize(stream), _ Report) End Using End If End Sub
下一课
在下一课中,您将学习如何编写用于更新从报表服务器加载的报表定义的代码。 请参阅 第 4 课:以编程方式更新报表定义。