第 4 课:以编程方式更新报表定义
新建日期: 2006 年 7 月 17 日
从报表服务器加载了报表定义并且通过报表字段拥有了对该报表定义的引用之后,需要更新报表定义。对本例来说,您将更新报表的 Description 属性。
更新报表定义
用以下代码替换 Program.cs 文件(对于 Visual Basic,为 Module1.vb)中 UpdateReportDefinition() 方法的代码:
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 课:将报表定义发布到报表服务器。