Partager via


Leçon 4 : Mettre à jour la définition de rapport par programmation

Maintenant que la définition de rapport a été chargée à partir du serveur de rapports et que vous avez une référence à celle-ci à l’aide du champ de rapport, vous devez mettre à jour la définition de rapport. Pour cet exemple, vous allez mettre à jour la Description propriété du rapport.

Pour mettre à jour la définition du rapport

  1. Remplacez le code de la méthode UpdateReportDefinition() dans le fichier Program.cs (Module1.vb pour Visual Basic) par le code suivant :

    private void UpdateReportDefinition()  
    {  
        System.Console.WriteLine("Updating Report Definition");  
    
        // Create a list of the Items Choices for the Report. The   
        // ItemsChoiceType118 enum represents all the properties  
        // available in the report and the ItemsElementName   
        // represents the properties that exist in the current   
        // instance of the report.  
        List<ItemsChoiceType118> _reportItems =   
            new List<ItemsChoiceType118>(_report.ItemsElementName);  
    
        // Locate the index for the Description property  
        int index = _reportItems.IndexOf(  
            ItemsChoiceType118.Description);  
    
        // The Description item is of type StringLocIDType, so   
        // cast the item type first and then assign new value.  
        System.Console.WriteLine("- Old Description: " +   
            ((StringLocIDType)_report.Items[index]).Value );  
    
        // Update the Description for the Report  
        ((StringLocIDType)_report.Items[index]).Value =   
            "New Report Description";  
    
        System.Console.WriteLine("- New Description: " +   
            ((StringLocIDType)_report.Items[index]).Value );  
    }  
    
    Private Sub UpdateReportDefinition()  
    
        System.Console.WriteLine("Updating Report Definition")  
    
        'Create a list of the Items Choices for the Report. The   
        'ItemsChoiceType118 enum represents all the properties  
        'available in the report and the ItemsElementName   
        'represents the properties that exist in the current   
        'instance of the report.  
        Dim reportItems As List(Of ItemsChoiceType118) = _  
            New List(Of ItemsChoiceType118)(m_report.ItemsElementName)  
    
        'Locate the index for the Description property  
        Dim index As Integer = _  
            reportItems.IndexOf(ItemsChoiceType118.Description)  
    
        'The Description item is of type StringLocIDType, so   
        'cast the item type first and then assign new value.  
        System.Console.WriteLine("- Old Description: " & _  
            DirectCast(m_report.Items(index), StringLocIDType).Value)  
    
        'Update the Description for the Report  
        DirectCast(m_report.Items(index), StringLocIDType).Value = _  
            "New Report Description"  
    
        System.Console.WriteLine("- New Description: " & _  
            DirectCast(m_report.Items(index), StringLocIDType).Value)  
    
    End Sub  
    

Leçon suivante

Dans la leçon suivante, vous allez enregistrer la définition de rapport mise à jour sur le serveur de rapports. Consultez la leçon 5 : Publier la définition de rapport sur le serveur de rapports.

Voir aussi

Mise à jour des rapports à l’aide de classes générées à partir du schéma RDL (didacticiel SSRS)