次の方法で共有


レッスン 3: レポート サーバーからレポート定義を読み込む

プロジェクトを作成し、RDL スキーマからクラスを生成したら、レポート サーバーからレポート定義を読み込む準備が整います。

レポート定義を読み込むには

  1. Report クラスのReportUpdater クラス (Visual Basic を使用している場合はモジュール) の先頭にプライベート フィールドを追加します。 このフィールドは、アプリケーションの有効期間中、レポート サーバーから読み込まれるレポートへの参照を維持するために使用されます。

    private Report _report;  
    
    Private m_report As Report  
    
  2. Program.cs ファイル内の LoadReportDefinition() メソッドのコード (Visual Basic の場合Module1.vb) を次のコードに置き換えます。

    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)