SQL 报告:空参数 [英] SQL Reporting: Null Parameter

查看:50
本文介绍了SQL 报告:空参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在 SQL Reporting 中可能存在问题.我的页面上有一个 ReportViewer,我使用以下方法发送参数:

I have discovered that in SQL Reporting there might be a problem. I have a ReportViewer on my page and I am sending in parameters using the following method:

List<ReportParameter> myParams = new List<ReportParameter>();

myParams.Add(new ReportParameter("Start_Date", StartDate));
myParams.Add(new ReportParameter("End_Date", EndDate));

ReportViewer1.ServerReport.SetParameters(myParams);

这很好用!但是,当我尝试将参数设置为 null 时,在运行该查询后,它会保留先前的值,而不是将其设置为 null.

This works great! But, when I try to set a parameter to null, after running that query, it maintains the previous value rather than setting it to null.

我在上述代码之后执行的另一个事件上运行此代码:

I run this code on another event that executes after the above code:

List<ReportParameter> myParams = new List<ReportParameter>();

myParams.Add(new ReportParameter("Start_Date")); 
// I even tried omiting this line.  
//(This is the null parameter I wish to pass)
myParams.Add(new ReportParameter("End_Date", EndDate));

ReportViewer1.ServerReport.SetParameters(myParams);

有没有人遇到过解决方法或不同的技术来实现这一目标?

Has anyone come across a work around or a different technique to get this working?

另外,如果我最初不定义参数,然后分配参数,然后不定义参数,它会保持分配的值.(这些都是回发,每个事件)

Also if I initially do not define the parameter, then assign the parameter, then do not define the paramter, it maintains the value that was assigned. (These are all postbacks, each event)

推荐答案

做这样的事情..我已经在我自己的小测试项目中测试过它,它似乎有效.

Do something like this..I've tested it in my own little test project and it seems to work.

List<ReportParameter> myParams = new List<ReportParameter>();

ReportParameter p = new ReportParameter("Start_Date");
p.Values.Add(null);
myParams.Add(p);

//myParams.Add(new ReportParameter("Start_Date")); 
// I even tried omiting this line.  
//(This is the null parameter I wish to pass)
myParams.Add(new ReportParameter("End_Date", EndDate));

ReportViewer1.ServerReport.SetParameters(myParams);

这篇关于SQL 报告:空参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆