I am using crystal report in my project in which i am having some btns (month,Day,Year) like when i click any btn among them report data should be shown only of that current month or day or year. i did this somehow for month btn .
private void button4_Click(object sender, EventArgs e)
{//month
crystalReportViewer1.ReportSource = null;
DateTime dtFrom = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
DateTime dtTo = dtFrom.AddMonths(1).AddDays(-1);
if (ReportName == "SalesReport")
{
Report.RecordSelectionFormula = String.Format("{0} >= CDate({1:yyyy,MM,dd}) And {0} <= CDate({2:yyyy,MM,dd})", "{BILLH.B_date}", dtFrom, dtTo);
crystalReportViewer1.ReportSource = this.Report;
crystalReportViewer1.Refresh();
}
else if (ReportName == "PurchaseReport")
{
Report.RecordSelectionFormula = String.Format("{0} >= CDate({1:yyyy,MM,dd}) And {0} <= CDate({2:yyyy,MM,dd})", "{PRO_BILL.P_purdate}", dtFrom, dtTo);
crystalReportViewer1.ReportSource = this.Report;
crystalReportViewer1.Refresh();
}
this code is working fine for month but now i want to do same for DAY btn ,i help me in this . thanks in advance .
this code is working fine for month but now i want to do same for DAY btn ,i help me in this . thanks in advance .

huang zhenhuaPosted Sep 6, 2014, 5:27 AM
DateTime dtFrom = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
DateTime dtTo = dtFrom;
2.when Year btn:
DateTime dtFrom = new DateTime(DateTime.Today.Year, 1, 1);
DateTime dtTo = dtFrom.AddYears(1).AddDays(-1);
Piyush PansuriyaPosted Sep 5, 2014, 2:10 AM
private void button4_Click(object sender, EventArgs e)
{
if ((sender as button).name =="Month")
{
DateTime dtFrom = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
DateTime dtTo = dtFrom.AddMonths(1).AddDays(-1);
}
else if ((sender as button).name =="Day")
{
DateTime dtFrom = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
DateTime dtTo = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
}
}