Share via


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

プロジェクトを作成し、RDL スキーマからクラスを生成すると、レポート定義をレポート サーバーから読み込めるようになります。

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

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

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

    private void LoadReportDefinition()
    {
        System.Console.WriteLine("Loading Report Definition");
    
        string reportPath = 
            "/AdventureWorks 2008 Sample Reports/Company Sales 2008";
    
        // Retrieve the report defintion 
        // 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 2008 Sample Reports/Company Sales 2008"
    
        'Retrieve the report defintion 
        '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 : プログラムによるレポート定義の更新」を参照してください。