我现在做到这一步:
1 private void saveReportButton_Click(object sender, System.EventArgs e) 2 { 3 Cursor.Current = Cursors.WaitCursor; 4 5 // Define variables needed for the Render() method. 6 string historyID = null; 7 string format = formatComboBox.Text; 8 rs2010.DataSourceCredentials[] credentials = null; 9 rs2010.ParameterValue[] reportHistoryParameters = null; 10 11 // Define variables needed for GetParameters() method 12 bool forRendering = false; 13 rs2010.ItemParameter[] parameters = null; 14 bool noDefault = false; 15 16 // Create a variable containing the selected item 17 selItem = ((CatalogListViewItem)reportListView.SelectedItems[0]).Item; 18 19 try 20 { 21 // If the report uses parameters for which there is no default 22 // value, then the report cannot be rendered and saved by this 23 // application 24 parameters = rs.GetItemParameters(selItem.Path, historyID, 25 forRendering, reportHistoryParameters, credentials); 26 string ss = ""; 27 int i = 0; 28 foreach (rs2010.ItemParameter parameter in parameters) 29 { 30 if (parameter.DefaultValues == null) 31 { 32 ReportParameter para = new ReportParameter(); 33 para.Name = parameter.Prompt; 34 para.DefaultValues[0] = "0"; 35 SaveAs(); 36 } 37 else 38 { 39 ss += "\nPrompt: " + parameter.Prompt + "\n DefaultValues[0]: " + parameter.DefaultValues[0]; 40 } 41 } 42 MessageBox.Show(ss); 43 44 if (noDefault) 45 { 46 MessageBox.Show( 47 Resources.missingDefaultParametersErrorMessage, 48 Resources.missingDefaultParametersMessageBoxTitle, 49 MessageBoxButtons.OK, 50 MessageBoxIcon.Error); 51 } 52 else 53 { 54 SaveAs(); 55 } 56 } 57 58 catch (Exception exception) 59 { 60 HandleException(exception); 61 } 62 63 finally 64 { 65 Cursor.Current = Cursors.Default; 66 } 67 }
在下面的判断里,我判断选定的报表参数默认值是否为 null ,如果为空就给其赋值。
因为parameter.DefaultValues == null,所以
parameter.DefaultValues = para.DefaultValues 的时候会报错 提示说什么因为没有实例化(null)。
1 if (parameter.DefaultValues == null) 2 { 3 ReportParameter para = new ReportParameter(); 4 para.Name = parameter.Prompt; 5 para.DefaultValues[0] = "0"; 6 parameter.DefaultValues = para.DefaultValues; 7 SaveAs(); 8 }
该怎么写才好啊。。。