Click here to Skip to main content
12,951,034 members (56,674 online)
Rate this:
Please Sign up or sign in to vote.
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.

private void button_Click()
 ReportDocument cryRpt = new ReportDocument();
            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;
            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;
            crParameterDiscreteValue.Value = dateTimePicker1.Value.ToString();
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["fromDate"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;
            crParameterDiscreteValue.Value = dateTimePicker2.Value.ToString();
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["toDate"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;
            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            crystalReportViewer2.ReportSource = cryRpt;

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 29-Aug-12 1:16am
Updated 29-Aug-12 11:30am
Sourav Sarkar-SS 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?
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,984
CHill60 3,460
Maciej Los 3,053
Jochen Arndt 1,975
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100