Freigeben über


Lektion 4: Programmgesteuertes Aktualisieren der Berichtsdefinition

Nachdem die Berichtsdefinition aus dem Berichtsserver geladen wurde und Sie mithilfe des Berichtsfelds darauf verweisen, müssen Sie die Berichtsdefinition aktualisieren. Im folgenden Beispiel wird die Description-Eigenschaft für den Bericht aktualisiert.

So aktualisieren Sie die Berichtsdefinition

  • Ersetzen Sie den Code für die UpdateReportDefinition()-Methode in der Datei Program.cs (Module1.vb für Visual Basic) durch folgenden Code:

    private void UpdateReportDefinition()
    {
        System.Console.WriteLine("Updating Report Definition");
    
        // Create a list of the Items Choices for the Report. The 
        // ItemsChoiceType80 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<ItemsChoiceType80> _reportItems = 
            new List<ItemsChoiceType80>(_report.ItemsElementName);
    
        // Locate the index for the Description property
        int index = _reportItems.IndexOf(
            ItemsChoiceType80.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 
        'ItemsChoiceType80 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 ItemsChoiceType80) = _
            New List(Of ItemsChoiceType80)(m_report.ItemsElementName)
    
        'Locate the index for the Description property
        Dim index As Integer = _
            reportItems.IndexOf(ItemsChoiceType80.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
    

Nächste Lektion

In der nächsten Lektion speichern Sie die aktualisierte Berichtsdefinition wieder auf dem Berichtsserver. Siehe Lektion 5: Veröffentlichen der Berichtsdefinition auf dem Berichtsserver.