记录报告
private void button1_Click(object sender, EventArgs e)
{
TR = Application.OpenForms.OfType<Records>().ElementAt(0);
try
{
ds = new DataSet2();
dt = new System.Data.DataTable();
dt = ConvertDGVtoDataTable(TR.recordsTableDataGridView);
ds.Tables.Add(dt);
ds.WriteXmlSchema("RecordsReport.xml");
try
{
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = dateTimePicker1.Value;
crParameterFieldDefinitions = treport1.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["fromDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crParameterDiscreteValue.Value = dateTimePicker2.Value;
crParameterFieldDefinitions = treport1.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["toDate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
// Report Form.
TReportDisplay TRD = new TReportDisplay();
Treport treport1 = new Treport();
TRD.crystalReportViewer2.ReportSource = treport1;
treport1.SetDataSource(ds);
TRD.Show();
TRD.crystalReportViewer2.Refresh();
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); };
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
}
我的报告有两个参数, fromDate 和 toDate ,两者都定义为日期时间, 谨慎的价值观。
我的选择记录公式如下:
如果我删除此公式,则报告将显示所有内容,但如果我输入此公式,则报告将显示为空白。
已解决:在我的情况下,我不会将数据库值用作“Arthi在此处出现” Filter data in crystal report using datetimepicker
答案 0 :(得分:1)
而不是dateTimePicker1.Value,请尝试以下方法:
crParameterDiscreteValue.Value = dateTimePicker1.Text;