Click here to Skip to main content
15,885,980 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I made a crystal report to retrieve data between two dates, but it shows only the column names

C#
SqlConnection con = new SqlConnection("Data Source=server;Initial Catalog=f_library;User ID=sa;Password=ahmed");
            con.Open();
            SqlDataAdapter dad = new SqlDataAdapter("Select * from absence  where absent_b_date between @start and @end", con);
            dad.SelectCommand.Parameters.AddWithValue("@start", dateTimePicker1.Value);
            dad.SelectCommand.Parameters.AddWithValue("@end", dateTimePicker2.Value);
            DataTable mDT_Report = new DataTable();
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("G:\\WindowsApplication2\\WindowsApplication2\\CrystalReport6.rpt");
         
            ParameterFieldDefinitions crParameterFieldDefinitions ;
            ParameterFieldDefinition crParameterFieldDefinition ;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = dateTimePicker1.Value;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["hireto"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

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

            crParameterDiscreteValue.Value = dateTimePicker2.Value;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["hirefrom"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

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

            dad.Fill(mDT_Report);
            cryRpt.Database.Tables[0].SetDataSource(mDT_Report);
            MessageBox.Show("Generating Report", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            crystalReportViewer1.ReportSource = cryRpt;
Posted
Updated 28-Feb-12 2:50am
v3
Comments
[no name] 28-Feb-12 6:11am    
What is your question?
iceprincess50 28-Feb-12 6:18am    
i made crystal report to retrivte data between two dates
but it show only column name
Dean Oliver 28-Feb-12 8:50am    
Yes that's your problem, but what do you want to have it do?

1 solution

Check this article
C# Crystal Reports - Date to Date[^]
 
Share this answer
 
Comments
Uday P.Singh 4-Mar-12 5:14am    
5!

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