SetParameterValue传入多个值的问题

xiaohua3006 2011-03-04 04:51:00
我有个Customer表,我想把里面的Country字段里面的数据全部取出来放到SetParameterValue
myReport.SetParameterValue("selectCountry","Country");
selectCountry是cr里面的一个参数名。
SetParameterValue好像可以保存list,把数据库里面的country写到一个类里面,
再实例化类,把list保存到SetParameterValue,这样行不?
不过这样我好像不会.
...全文
524 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaohua3006 2011-03-08
  • 打赏
  • 举报
回复

string sqlselectCountry = "select distinct Country from Customer";
OleDbDataAdapter daCountry = new OleDbDataAdapter(sqlselectCountry, cn);
DataSet dset = new DataSet();
daCountry.Fill(dset, "sCountry");

ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
// 设置参数字段的名称,它必须
//和报表中的参数相符。
paramField.ParameterFieldName = "selectCountry";

// 设置第离散值并将其传递给该参数。
foreach (DataRow item in dset.Tables["sCountry"].Rows)
{
discreteVal = new ParameterDiscreteValue();
discreteVal.Value = item[0].ToString();
paramField.CurrentValues.Add(discreteVal);
}

// 将该参数添加到参数字段集合。
paramFields.Add(paramField);

// 将参数字段集合放入查看器控件。
this.CrystalReportViewer1.ParameterFieldInfo = paramFields;

报表里面的筛选是{Customer.Country} in {?selectCountry}。

这样传值没有问题,页面可以把所以的信息全部都打印出来.
但是我想要的效果是根据country这个参数来选择一个或者多个country来进行筛选,
而这样写的话是把所以的country默认的都传过去了!
xiaohua3006 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 luols 的回复:]

水晶报表 之 多值参数传入【推荐】
[/Quote]
遇到个问题,但是不知道是什么问题,
经过调试pvs里面的值是正确的,是预期的结果,不过当运行选择参数的时候发现参数字段里面一个值都没有,
请问一下这是什么情况呢?

string sqlselectCountry = "select distinct Country from Customer";
OleDbDataAdapter daCountry = new OleDbDataAdapter(sqlselectCountry, cn);
DataSet dset = new DataSet();
daCountry.Fill(dset, "sCountry");

ParameterDiscreteValue pv;
ParameterValues pvs = new ParameterValues();
pv = new ParameterDiscreteValue();

foreach (DataRow item in dset.Tables["sCountry"].Rows)
{
pv.Value = item[0].ToString();
pvs.Add(pv);
}

myReport.SetParameterValue("selectCountry", pvs);

报表里面的筛选是{Customer.Country} in {?selectCountry}。
xiaohua3006 2011-03-07
  • 打赏
  • 举报
回复
在我运行了项目之后会有个选择参数的页面,选择了参数以后点击提交就会把报表展示出来.

如果我不在报表文件的{?selectCountry}这个参数字段里面设置默认值的话那个使用值就不会出现,
而且里面也没有我从myReport.SetParameterValue("selectCountry", pvs);里面传过来的值...
阿双2009 2011-03-07
  • 打赏
  • 举报
回复
你 选择参数的时候 是什么时候?

4,816

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧