Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,
I want to create a Crystal Report in a particular task between two dates. Here I am passing all the above three. But I can't get the report between two dates. Here is my code for you to check. Please help me find what needs to be changed. My code generates a report for all dates.

C#
private void button_Click()
{
 ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(@"Reports\DatewiseSupplierReport.rpt");
            frm_ReportForm _report = new frm_ReportForm();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;
            SqlConnection con = new SqlConnection();
            string[] conString = DBSettings.connectionStringValues();
            string connectionString = string.Format(@"server=" + conString[0] + ";database=restaurant;uid=" + conString[2] + ";pwd=" + conString[3]);
            con.ConnectionString = connectionString;
            con.Open();
            crConnectionInfo.ServerName = conString[0];
            crConnectionInfo.DatabaseName = "restaurant";
            crConnectionInfo.UserID = conString[2];
            crConnectionInfo.Password = conString[3];

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            
            crParameterDiscreteValue.Value = cmb_SupplierName.Text;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["SupplierName"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crParameterDiscreteValue.Value = dateTimePicker1.Value.ToString();
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["fromDate"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crParameterDiscreteValue.Value = dateTimePicker2.Value.ToString();
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["toDate"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

            crystalReportViewer2.ReportSource = cryRpt;
            crystalReportViewer2.Refresh();  

}

In the above, I get SupplierName from combobox(cmb_SupplierName)
The two dates I get are from datetimepicker1 and 2.

Thanks in Advance

Dhinesh Kumar.V
Posted
Updated 29-Aug-12 11:30am
v2
Comments
[no name] 29-Aug-12 15:31pm    
can you use SqlDataAdapter and DataSet.
Then I can help you with a very small code which may help you?
BTW
Use Pre tags to quote the code part for better readability.
ChandraRam 30-Aug-12 8:41am    
The report filters for supplier correctly? Check that your parameters are actually being applied to the report - you can do this by temporarily displaying the parameters in one of the report sections (report header, for instance).

1 solution

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