Click here to Skip to main content
15,891,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a form with CrystalReportViewer and on the top there are two DateTimePickers with on button for generating a crystal report with the selected date range, this is my code its work, but my question is how can I Prevent default "Enter Parameter Value" dialog box display, because I want to use only my datetimepickers.


C#
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;
            crystalReportViewer1.Refresh();
        }
Posted

CodeProject is your friend; the sooner you learn to use the search facility here, the more productive you'll be :) See Thatraja's answer here: [^].

And, since you know how to post a question on StackOverFlow, why not also easily find an answer there: [^].
 
Share this answer
 
Comments
R.M49 31-Oct-15 7:34am    
I copy this code and used it exactly but it also show the "Enter Parameter Value"

http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-date-parameter.htm
To set parameter on crystal I always do it this way:

C#
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(reportPath);
reportDocument.SetParameterValue("@id", YourParameterValue);

if you want to convert your report to a pdf:

C#
var exportOptions = reportDocument.ExportOptions;
exportOptions.ExportDestinationType = ExportDestinationType.NoDestination;
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
var req = new ExportRequestContext {ExportInfo = exportOptions};
var stream = reportDocument.FormatEngine.ExportToStream(req);


this returns you back a filestream that you can open from the aspx page.
 
Share this answer
 
Comments
R.M49 31-Oct-15 7:43am    
My code is work correctly I am only want to stop displaying the "Enter Parameter Value"
BillWoodruff 31-Oct-15 8:25am    
Are you saying the code in this solution does not work for you ?
R.M49 31-Oct-15 8:44am    
No I doesn't
Debojyoti Saha 31-Oct-15 8:27am    
Removing the code
CrystalReportViewer1.RefreshReport()
R.M49 31-Oct-15 8:55am    
this doesn't work, the windows still appear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900