共用方式為


第 3 課:從報表伺服器載入報表定義

在您建立專案並從 RDL 結構描述產生類別之後,就可以開始從報表伺服器載入報表定義。

載入報表定義

  1. 如果您使用類別的 Visual Basic) ,請在類別 (ReportUpdater 模組頂端新增私用 Report 欄位。 此欄位將用來在應用程式使用期間,維護從報表伺服器載入的報表參考。

    private Report _report;  
    
    Private m_report As Report  
    
  2. 以下列程式碼 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 課:以程式設計方式更新報表定義

另請參閱

使用 RDL 結構描述產生的類別更新報表 (SSRS 教學課程)
報表定義語言 (SSRS)