Click here to Skip to main content
12,943,299 members (74,886 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();
            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 29-Aug-12 1:16am
Updated 29-Aug-12 11:30am
Kschuler35.3K
v2
Comments
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?
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,643
CHill60 2,930
Maciej Los 2,328
Jochen Arndt 1,900
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web02 | 2.8.170518.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