reportviewer控件使用中碰到的问题,急需解决,帮帮忙!
在本地模式下,按照向导完成报表的设计后。要实现通过查询将结果显示在报表上。reportviewer在与数据源连接时是通过objectdatasource控件来实现的。所以对数据的查询转化到对objectdatasource控件的命令参数的控制。但当objectdatasource命令参数的参数源来自控件时(如文本框的内容),传递的是字符串类型。有时与参数的类型(假设是datatime)不匹配。该怎么转换?objectdatasource控件没有提供对参数值的设置,而DataSet1.xsd文件中的TableAdapter中的查询生成器又不提供对参数的类型声明,这要怎么解决?
[解决办法]
沙发帮忙顶
[解决办法]
是cr(crystal report)吗?
[解决办法]
参考代码:
SqlParameter[] conditionParameter = new SqlParameter[] { new SqlParameter("@Year",ddlYear.SelectedValue) }; ReportParameter[] param = new ReportParameter[] { new ReportParameter("ReportParameterYear", ddlYears.SelectedItem.Text.ToString()), }; //Get Data into dataset string thisConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection thisConnection = new SqlConnection(thisConnectionString); DataSet thisDataSet = new DataSet(); thisDataSet = SqlHelper.ExecuteDataset(thisConnection, "uspXXX", conditionParameter); ReportDataSource datasource = new ReportDataSource("dsxxx_uspxxx", thisDataSet.Tables[0]); //Displayed in ReportVierer ReportViewer1.Visible = true; ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(datasource); if (thisDataSet.Tables[0].Rows.Count == 0) { lblMessage.Text = "xxxx!"; } else { lblMessage.Text = String.Empty; } ReportViewer1.LocalReport.SetParameters(param); ReportViewer1.LocalReport.Refresh(); }
[解决办法]
先转换好了再给数据源啊