用C#2005做程序,做到了报表预览功能,报表设计好了,预览窗口中加入了reportviewer控件,系统自动加入了BindingSource控件,现在已经能够正常预览报表和打印了。
我想预览窗口打开时能够执行过滤、排序功能,我在预览窗口的load事件中加入了BindingSource.Filter = "过滤语句"和BindingSource.Sort = "排序语句"希望能够在窗口打开时自动过滤、排序记录,但是无论怎样改,预览窗口打开时始终显示全部记录。
我想可能是reportviewer控件默认完全读取dataset里的全部数据,不管后面怎样筛选、排序都没用。我将tableadapter里配置的sql语句改成我需要的select * from jinhuobiao,xiaoshou where xiaoshou.jhbh = jinhuobiao.bh and yhxm like '%王%' 命令,显示就正确了。但是报表过滤、排序的条件不是固定的,是操作者来选择的,不知怎样用代码在程序中修改tableadapter里配置的sql语句(即窗口Load事件中系统自动添加的this.lirunTableAdapter.Fill(this.JiameiDataSet.lirun)语句,Fill就是执行tableadapter里配置的sql语句)????
后来我将系统自动添加的BindingSource控件删除了,想通过程序代码来实现加载,代码如下:
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控件中,请问是什么原因请高手指点一下,做数据库程序都要用到报表预览打印功能,如果报表不能按用户要求对记录进行筛选、排序,c#2005里的RDLC报表功能还有什么用???
我想预览窗口打开时能够执行过滤、排序功能,我在预览窗口的load事件中加入了BindingSource.Filter = "过滤语句"和BindingSource.Sort = "排序语句"希望能够在窗口打开时自动过滤、排序记录,但是无论怎样改,预览窗口打开时始终显示全部记录。
我想可能是reportviewer控件默认完全读取dataset里的全部数据,不管后面怎样筛选、排序都没用。我将tableadapter里配置的sql语句改成我需要的select * from jinhuobiao,xiaoshou where xiaoshou.jhbh = jinhuobiao.bh and yhxm like '%王%' 命令,显示就正确了。但是报表过滤、排序的条件不是固定的,是操作者来选择的,不知怎样用代码在程序中修改tableadapter里配置的sql语句(即窗口Load事件中系统自动添加的this.lirunTableAdapter.Fill(this.JiameiDataSet.lirun)语句,Fill就是执行tableadapter里配置的sql语句)????
后来我将系统自动添加的BindingSource控件删除了,想通过程序代码来实现加载,代码如下:
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控件中,请问是什么原因请高手指点一下,做数据库程序都要用到报表预览打印功能,如果报表不能按用户要求对记录进行筛选、排序,c#2005里的RDLC报表功能还有什么用???
Me.dataset.user_list.DefaultView.RowFilter = "你自己的条件"
Me.user_listReportBindingSource.DataSource = Me.dataset.user_list.DefaultView
Me.ReportViewer1.RefreshReport()
我也找了半天才找到 sort也可以这么用