我有一个带有CrystalReportViewer的表单,顶部有两个带有按钮的DateTimePickers,用于生成具有所选日期范围的水晶报表,这是我的代码工作,但我的问题是如何防止默认&#34 ;输入参数值"对话框显示,因为我只想使用我的datetimepickers。
private void button1_Click_1(object sender, EventArgs e)
{
ReportDocument RepDoc = new ReportDocument();
RepDoc.Load(@"C:****I Put the path of report here");
SqlConnection con = new SqlConnection(@"I Put the Data Source here");
SqlDataAdapter sda = new SqlDataAdapter("Select * from Items", con);
StockDBDataSet ds = new StockDBDataSet();
sda.Fill(ds, "Items");
RepDoc.SetDataSource(ds);
ParameterFieldDefinitions ParameterFieldDefinitions;
ParameterFieldDefinition ParameterFieldDefinition;
ParameterValues ParameterValues = new ParameterValues();
ParameterDiscreteValue ParameterDiscreteValue = new ParameterDiscreteValue();
ParameterDiscreteValue.Value = dateTimePicker1.Value;
ParameterFieldDefinitions = RepDoc.DataDefinition.ParameterFields;
ParameterFieldDefinition = ParameterFieldDefinitions["Start_Date"];
ParameterValues = ParameterFieldDefinition.CurrentValues;
ParameterValues.Clear();
ParameterValues.Add(ParameterDiscreteValue);
ParameterFieldDefinition.ApplyCurrentValues(ParameterValues);
ParameterDiscreteValue.Value = dateTimePicker2.Value;
ParameterFieldDefinitions = RepDoc.DataDefinition.ParameterFields;
ParameterFieldDefinition = ParameterFieldDefinitions["End_Date"];
ParameterValues = ParameterFieldDefinition.CurrentValues;
ParameterValues.Clear();
ParameterValues.Add(ParameterDiscreteValue);
ParameterFieldDefinition.ApplyCurrentValues(ParameterValues);
crystalReportViewer1.ReportSource = RepDoc;
}
答案 0 :(得分:0)
尝试包含此行。
crystalReportViewer1.ParameterFieldInfo = RepDoc.ParameterFields;
我认为应该为你做这件事。