我正在 Crystal Reports C# windows 应用程序中处理报表.我从 localhost 服务器获取数据到 Crystal 报表.我的表单中有 2 个 datetimepicker.
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 = dtpfrom
datetimepicker1 = dtpfrom
datetimepicker2 - dtpto
datetimepicker2 - dtpto
水晶报告
现在我想要那个,当在 from 和 to datetimepicker 中选择某个日期时,数据之间的数据显示在水晶报告中,请帮助我解决我不知道如何开始的问题.我正在通过谷歌搜索我没有得到关于水晶报告中 datetimepicker 显示的数据之间的任何信息.有什么想法吗?
Now 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?
这是我的尝试:
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 中
An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.DataSourceException' occurred in CrystalDecisions.ReportAppServer.DataSetConversion.dll
附加信息:加载数据库信息失败.
Additional information: Failed to load database information.
在线:
objcr.SetDataSource(dt);
@divi
使用 datetimepicker 过滤报告中的数据不是为您的编码完成的
filter data in report using datetimepicker is not done for your coding
执行以下操作:
在字段资源管理器中创建一个新参数fromdate,todate -> 参数字段(右键单击)-> 新建
create a new parameter fromdate, todate in Field Explorer -> Parameter Field(Right Click)-> New
像这样也使今天成为今天
like this make todate also
然后右键单击报告.
选择报表 -> 选择公式 -> 记录...
Select Report -> Selection Formula -> Record...
关注
然后单击该表单中的保存并关闭按钮.
then click save and close button in that form.
知道这一点:
右击报表 -> 数据库 -> 设置数据源位置...
Right Click the report -> Database -> Set Datasource Location...
现在编码
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 过滤水晶报表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!