Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# , +
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
Edited 29-Aug-12 11:30am
Kschuler32.4K
v2
Comments
Sourav Sarkar-SS at 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 at 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
0 Sergey Alexandrovich Kryukov 368
1 Richard MacCutchan 240
2 OriginalGriff 230
3 Jared Sanow 145
4 Vinay Mistry 133
0 Sergey Alexandrovich Kryukov 5,955
1 OriginalGriff 4,805
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2014
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