Поделиться через


Занятие 4. Обновление определения отчета программным способом

Добавления: 17 июля 2006 г.

После загрузки определения отчета с сервера отчетов и при наличии ссылки на него через поле отчета необходимо обновить определение отчета. В этом примере будет обновлено свойство Description отчета.

Обновление определения отчета

  1. Замените код метода UpdateReportDefinition() в файле Program.cs (Module1.vb для Visual Basic) следующим кодом:

    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
    

Следующее занятие

На следующем занятии обновленное определение отчета будет сохранено назад на сервер отчетов. См. раздел Занятие 5. Публикация определения отчета на сервере отчетов.

См. также

Задачи

Учебник. Обновление отчетов с помощью классов, созданных из RDL-схемы

Другие ресурсы

Report Definition Language

Справка и поддержка

Получение помощи по SQL Server 2005