3단원: 보고서 서버에서 보고서 정의 로드
프로젝트를 만들고 RDL 스키마에서 클래스를 생성하면 보고서 서버에서 보고서 정의를 로드할 준비가 됩니다.
보고서 정의를 로드하려면
Report 클래스에 대한 ReportUpdater 클래스(Visual Basic을 사용 중인 경우 모듈)의 맨 위에 private 필드를 추가합니다. 이 필드는 응용 프로그램의 수명이 지속되는 동안 보고서 서버에서 로드된 보고서에 대한 참조를 유지 관리하는 데 사용됩니다.
private Report _report;
Private m_report As Report
Program.cs 파일(Visual Basic의 경우 Module1.vb)에서 LoadReportDefinition() 메서드의 코드를 다음 코드로 바꿉니다.
private void LoadReportDefinition() { System.Console.WriteLine("Loading Report Definition"); string reportPath = "/AdventureWorks Sample Reports/Company Sales"; // Retrieve the report defintion // from the report server byte[] bytes = _reportService.GetReportDefinition(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 Sample Reports/Company Sales" 'Retrieve the report defintion 'from the report server Dim bytes As Byte() = _ m_reportService.GetReportDefinition(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