Filter Issue between two dates in crystal report

Last Reply 12 days ago By Andrea

Posted 12 days ago

I want to fetch record between two dates in crystal report but it is not filtering here is my html


<asp:TextBox ID="txtFromDate" runat="server" Text="01-08-2018"></asp:TextBox>
<asp:TextBox ID="txtToDate" runat="server" Text="08-08-2018"></asp:TextBox>
<asp:Button ID="btnSearchTerm" runat="server" Text="Filter"
onclick="btnSearchTerm_Click"  />
<br />

<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
Height="1000" Width="1000" BestFitPage="true" ToolPanelView="None" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" />

and Code is


protected void btnSearchTerm_Click(object sender, EventArgs e)
string fromDate = txtFromDate.Text.Trim();
string toDate = txtToDate.Text.Trim();

ReportDocument crystalReport = new ReportDocument();
crystalReport.SetDatabaseLogon("sa", "2005", @"alhamd-PC", "Working");
StuDS dsPersonInformations = GetEmployees(fromDate, toDate);
CrystalReportViewer1.ReportSource = crystalReport;

private StuDS GetEmployees(string fromDate, string toDate)
string conString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
//SqlCommand cmd = new SqlCommand("SELECT * FROM Employees WHERE CONVERT(DATETIME,BirthDate,103) BETWEEN CONVERT(DATETIME,@FromDate,103) AND CONVERT(DATETIME,@ToDate,103)");
SqlCommand cmd = new SqlCommand("select AdmissionNo,AdmissionDate,SName,FName from tblStdReg where AdmissionDate between @FromDate and @ToDate");
using (SqlConnection con = new SqlConnection(conString))
using (SqlDataAdapter sda = new SqlDataAdapter())
cmd.Connection = con;
cmd.Parameters.AddWithValue("@FromDate", fromDate);
cmd.Parameters.AddWithValue("@ToDate", toDate);
sda.SelectCommand = cmd;
using (StuDS dsEmployees = new StuDS())
sda.Fill(dsEmployees, "StuDT");
return dsEmployees;

and screenshoot is 


You are viewing reply posted by: Andrea 12 days ago.
Posted 12 days ago
Hi @smile,
Please try the following

Filter Crystal Report between two Dates from VARCHAR column in ASP.Net

It might help you.

Cheers Andrea.