Share via


Leçon 3 : Chargement d'une définition de rapport à partir du serveur de rapports

Nouveau : 17 juillet 2006

Après avoir créé votre projet et généré les classes à partir du schéma RDL, vous êtes prêt à charger une définition du rapport depuis le serveur de rapports.

Pour charger une définition de rapport

  1. Ajoutez un champ privé au début de la classe (ou du module en Visual Basic) ReportUpdater pour la classe Report. Ce champ sera utilisé pour conserver une référence au rapport chargé depuis le serveur de rapports pendant la vie de l'application.

    private Report _report;
    
    Private m_report As Report
    
  2. Remplacez le code de la méthode LoadReportDefinition() du fichier Program.cs (Module1.vb en Visual Basic) par le code suivant :

    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
    

Leçon suivante

Dans la leçon suivante, vous allez écrire le code permettant de mettre à jour la définition du rapport chargée depuis le serveur de rapports. Voir Leçon 4 : Mise à jour par programme de la définition du rapport.

Voir aussi

Tâches

Didacticiel : Mise à jour des rapports utilisant les classes générées à partir du schéma RDL

Autres ressources

Report Definition Language

Aide et Informations

Assistance sur SQL Server 2005