报表预览reportviewer控件如何自动过滤、排序记录
用C#2005做程序,做到了报表预览功能,报表设计好了,预览窗口中加入了reportviewer控件,系统自动加入了BindingSource控件,现在已经能够正常预览报表和打印了。我想预览窗口打开时能够执行过滤、排序功能,我在预览窗口的load事件中加入了BindingSource.Filter = "过滤语句"和BindingSource.Sort = "排序语句"希望能够在窗口打开时自动过滤、排序记录,但是无论怎样改,预览窗口打开时始终显示全部记录,不知有什么方法能做到我要的功能?谢谢
private void Form_view_Load(object sender, EventArgs e)//预览窗口load事件
{
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("JiameiDataSet_lirun",loaddata()));
this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
reportViewer1.RefreshReport();
}
private DataTable loaddata()
{
SqlConnection con = new SqlConnection("server=star;user id=yw;pwd=qianye;database=jiamei;connection timeout=3");
SqlCommand cmd=new SqlCommand("select * from jinhuobiao,xiaoshou where xiaoshou.jhbh = jinhuobiao.bh and yhxm like '%王%'",con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
JiameiDataSet ds=new JiameiDataSet();
adp.Fill(ds);
return ds.Tables[0];
}
但是在运行程序打开预览窗口时,reportViewer控件中却显示“报表处理已取消”,然后出现一个只有标题的表格,数据内容一行都没有,说明数据没有加载到reportViewer控件中,请问是什么原因 有人知道吗,没人碰到这种问题吗 我想可能是reportviewer控件默认完全读取dataset里的全部数据,不管后面怎样筛选、排序都没用。我将tableadapter里配置的sql语句改成我需要的select * from jinhuobiao,xiaoshou where xiaoshou.jhbh = jinhuobiao.bh and yhxm like '%王%' 命令,显示就正确了。
问题是怎样用代码在程序中修改tableadapter里配置的sql语句????
请帮帮忙,这个问题好长时间了 顶一下 看一看我这个贴子,可以实现你的功能
也希望你能解决此贴子里的问题
[url=http://bbs.bccn.net/viewthread.php?tid=224597&highlight=%B1%A8%B1%ED]http://bbs.bccn.net/viewthread.php?tid=224597&highlight=%B1%A8%B1%ED[/url]
页:
[1]
