Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to fetch data from sql server database in crystal report with the help of two date time-pickers values selection using c# window form, user will select two dates from date-time pickers and crystal report should be generate between those two date , I have a problem when I select two dates , I do not get the correct result when I select dates form date time pickers but when I select from parameters interface of crystal report it gives me correct result kindly help me its urgent.
Posted
Comments
[no name] 25-Oct-14 11:04am    
If this were truly "urgent" then you would have described the problem. "I have a problem" is not a question and it is not a description of a problem. We would have no idea at all what you think the "correct result" would be, what the data is, what code you have written or anything else.
Attiq Ur Rehman 25-Oct-14 11:10am    
I m sorry I m new here, Actually I want to get data between two dates but when I select two dates it do-not return me the records between those two date which I have selected from date time pickers it gives me some random records that is my problem.
Attiq Ur Rehman 25-Oct-14 11:12am    
this is the code I have written

and this is the formula I have written to fetch the records

{Materials.Date} >= {?FromDate}
and
{Materials.Date} <= {?Todate}


private void CreateRpt_Click(object sender, EventArgs e)
{



ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(loc);

TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;

ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

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

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

crParameterDiscreteValue.Value = ToDate.Text.ToString();
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["Todate"];
crParameterValues = crParameterFieldDefinition.CurrentValues;

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

crConnectionInfo.ServerName = "(local)";
crConnectionInfo.DatabaseName = "ManagementSystem";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "12345";

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

crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}

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