Partilhar via


Lição 4: Atualizar a definição de relatório programaticamente

Agora que a definição do relatório foi carregada do servidor de relatório e você tem uma referência a ele usando o campo de relatório, você precisa atualizar a definição do relatório. Para este exemplo, você atualizará a Description propriedade do relatório.

Para atualizar a definição do relatório

  1. Substitua o código do método UpdateReportDefinition() no arquivo Program.cs (Module1.vb para Visual Basic) pelo seguinte código:

    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  
    

Próxima lição

Na próxima lição, você salvará a definição de relatório atualizada de volta para o servidor de relatório. Confira a lição 5: publicar a definição de relatório no servidor de relatório.

Consulte Também

Atualizando relatórios usando classes geradas a partir do esquema RDL (Tutorial do SSRS)