本文介绍了使用datetimepicker过滤水晶报告中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在处理一个报表在水晶报表C#Windows应用程序。从本地主机服务器获取数据水晶报表。我的表单中有2个datetimepicker。 datetimepicker1 = dtpfrom datetimepicker2 - dtpto Crystalreport 现在我想要的是,当选择一些日期时,从datetimepicker中,数据之间显示水晶报告请帮我解决我不知道怎么开始。我搜索通过googling我没有得到任何关于datetimepicker中的数据之间显示在水晶报告。任何想法? 这里我尝试: MySqlConnection conn = new MySqlConnection(MyCon); CrystalReport1 objcr = new CrystalReport1(); MySqlDataAdapter da = new MySqlDataAdapter(select * from data where date> ='+ DateTime.Parse(dtpfrom.Text)+'and date< ='+ DateTime.Parse(dtpto.Text)+ ',conn); DataTable dt = new DataTable(); da.Fill(dt); objcr.SetDataSource(dt); crystalReportViewer1.ReportSource = objcr; crystalReportViewer1.RefreshReport(); 但我收到了错误 未处理的类型为的异常'CrystalDecisions.CrystalReports.Engine.DataSourceException'出现在CrystalDecisions.ReportAppServer.DataSetConversion.dll中 其他信息:无法加载数据库信息。 在线: $ b b objcr.SetDataSource(dt); 解决方案 @divi 使用datetimepicker筛选报告中的数据未针对您的编码进行 执行以下操作: $ b 在字段资源管理器中创建一个新的参数fromdate,todate - >参数字段(右键) - >新建 像这样make todate也 然后右键单击报告。 选择报告 - >选择公式 - >记录... 执行以下操作: 右键点击报告 - >数据库 - >设置数据源位置... 现在代码 ReportDocument report = new ReportDocument report.Load(C:\\Users\\Desktop\\CrystalReport1.rpt); TableLogOnInfo Table = new TableLogOnInfo(); ConnectionInfo Connection = new ConnectionInfo(); 表表; ParameterFieldDefinitions参数; ParameterFieldDefinition参数; ParameterValues Values = new ParameterValues(); ParameterDiscreteValue DiscreteValue = new ParameterDiscreteValue(); DiscreteValue.Value = dateTimePicker1.Text; Parameters = report.DataDefinition.ParameterFields; Parameter = Parameters [fromdate]; Values = Parameter.CurrentValues; Values.Clear(); Values.Add(DiscreteValue); Parameter.ApplyCurrentValues(Values); DiscreteValue.Value = dateTimePicker2.Text; Parameters = report.DataDefinition.ParameterFields; Parameter = Parameters [todate]; Values = Parameter.CurrentValues; Values.Add(DiscreteValue); Parameter.ApplyCurrentValues(Values); Connection.ServerName =您的服务器名称在设置数据源位置; Connection.DatabaseName =您的数据库名称在设置数据源位置; Connection.UserID =您的用户名; Connection.Password =your password; Tables = report.Database.Tables; foreach(表中的CrystalDecisions.CrystalReports.Engine.Table表) { Table = table.LogOnInfo; Table.ConnectionInfo = Connection; table.ApplyLogOnInfo(Table); } crystalReportViewer1.ReportSource = report; crystalReportViewer1.Refresh(); 希望这有助于解决您的问题。 I'm working on a report in Crystal Reports C# windows application.i fetch the data from localhost server to crystal report. I have 2 datetimepicker in my form.datetimepicker1 = dtpfromdatetimepicker2 - dtptoCrystalreportNow I want that, when selecting some date in from and the to datetimepicker the between data is show in the crystal report please help me to solve i don't know how to start. i'm searching through googling i didn't get any thing about between data in datetimepicker show in crystal report. Any ideas?Here my try:MySqlConnection conn = new MySqlConnection(MyCon); CrystalReport1 objcr = new CrystalReport1(); MySqlDataAdapter da = new MySqlDataAdapter("select * from data where date>='" + DateTime.Parse(dtpfrom.Text) + "' and date<='" + DateTime.Parse(dtpto.Text) + "' ", conn); DataTable dt = new DataTable(); da.Fill(dt); objcr.SetDataSource(dt); crystalReportViewer1.ReportSource = objcr; crystalReportViewer1.RefreshReport();But i'm getting an error An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.DataSourceException' occurred in CrystalDecisions.ReportAppServer.DataSetConversion.dll Additional information: Failed to load database information.On line:objcr.SetDataSource(dt); 解决方案 @divifilter data in report using datetimepicker is not done for your codingDo the following:create a new parameter fromdate, todate in Field Explorer -> Parameter Field(Right Click)-> Newlike this make todate alsothen right click the report.Select Report -> Selection Formula -> Record...Do followingthen click save and close button in that form.Know this:Right Click the report -> Database -> Set Datasource Location...Now Code ReportDocument report = new ReportDocument(); report.Load("C:\\Users\\Desktop\\CrystalReport1.rpt"); TableLogOnInfo Table = new TableLogOnInfo(); ConnectionInfo Connection = new ConnectionInfo(); Tables Tables; ParameterFieldDefinitions Parameters; ParameterFieldDefinition Parameter; ParameterValues Values = new ParameterValues(); ParameterDiscreteValue DiscreteValue = new ParameterDiscreteValue(); DiscreteValue.Value = dateTimePicker1.Text; Parameters = report.DataDefinition.ParameterFields; Parameter = Parameters["fromdate"]; Values = Parameter.CurrentValues; Values.Clear(); Values.Add(DiscreteValue); Parameter.ApplyCurrentValues(Values); DiscreteValue.Value = dateTimePicker2.Text; Parameters = report.DataDefinition.ParameterFields; Parameter = Parameters["todate"]; Values = Parameter.CurrentValues; Values.Add(DiscreteValue); Parameter.ApplyCurrentValues(Values); Connection.ServerName = "Your servername in Set Datasource Location"; Connection.DatabaseName = "Your databasename in Set Datasource Location"; Connection.UserID = "your username"; Connection.Password = "your password"; Tables = report.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table table in Tables) { Table = table.LogOnInfo; Table.ConnectionInfo = Connection; table.ApplyLogOnInfo(Table); } crystalReportViewer1.ReportSource = report; crystalReportViewer1.Refresh();Hope This helps to solve your problem. 这篇关于使用datetimepicker过滤水晶报告中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-04 03:26