Compartir a través de


Lección 4: Actualizar la definición del informe mediante programación

Ahora que se ha cargado la definición del informe desde el servidor de informes y que el campo del informe le proporciona una referencia a la definición del informe, necesita actualizarla. En este ejemplo, actualizará la propiedad Description para el informe.

Para actualizar la definición del informe

  • Reemplace el código del método UpdateReportDefinition() en el archivo Program.cs (Module1.vb para Visual Basic) por el siguiente código:

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

Lección siguiente

En la siguiente lección, aprenderá a guardar la definición del informe actualizada en el servidor de informes. Vea Lección 5: Publicar la definición de informe en el servidor de informes.