如何将null
参数传递到 SQL 2008 报告中?ReportExecutionService.Render()
在我通过调用方法设置参数(不包括可为空的参数)之后,与 ReportExecution 和 ReportService2005 Web 服务接口的代码在执行该方法时总是会产生错误ReportExecutionService.SetExecutionParameters()
:
"...This report requires a default or user-defined value for the report parameter...to run or subscribe to this report, you must provide a parameter value."
即使该参数在 .rdl 文件中定义为null
能够,并且默认为null
.
我必须更改我的代码吗?更改 .rdl 文件中的参数选项?
var rs = new ReportExecutionService();
rs.Url= "http://Z/ReportServer/ReportExecution2005.asmx";
rs.Credentials = CredentialCache.DefaultCredentials;
rs.ExecutionHeaderValue = new ExecutionHeader();
var executionInfo = rs.LoadReport(ReportTarget, null);
var parameterList = new List<ParameterValue>();
foreach (ParameterValue parameter in Parameters)
{
parameterList.Add(parameter);
}
foreach (var expectedParameter in executionInfo.Parameters)
{
if
(
expectedParameter.Nullable &&
!parameterList.Exists(delegate(ParameterValue pv)
{ return pv.Name == expectedParameter.Name; })
)
{
var parameter = new ParameterValue();
parameter.Name = expectedParameter.Name;
parameter.Value = null;
parameterList.Add(parameter);
}
}
rs.SetExecutionParameters(parameterList.ToArray(), "en-us");
Warning[] warnings = null;
string[] streamIDs = null;
string encoding = null;
string extension = null;
string mime = null;
var content = rs.Render("PDF", null, out extension, out mime, out encoding, out warnings, out streamIDs);