indradeo says:
using
(SqlCommand cmd =
new
SqlCommand(
"select DISTINCT a.emp_id,a.emp_nm,a.dept,a.agncy,a.lcn,a.dsc,c.prtcpnt,d.cmplnc,e.ttc,a.dt,a.mnth from nmr a,emp b,pptlk c,sdor d,ttc e WHERE dt BETWEEN "
+ txtStartDate.Text +
"and"
+ txtEndDate.Text +
""
))
There is no space between Dates and AND operator.
Instead of using string concatenation use parameterized query.
Refer below modified code.
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select DISTINCT a.emp_id,a.emp_nm,a.dept,a.agncy,a.lcn,a.dsc,c.prtcpnt,d.cmplnc,e.ttc,a.dt,a.mnth from nmr a,emp b,pptlk c,sdor d,ttc e WHERE dt BETWEEN @Start and @End"))
{
cmd.Parameters.AddWithValue("@Start", txtStartDate.Text.Trim());
cmd.Parameters.AddWithValue("@End", txtEndDate.Text.Trim());
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
Also make sure you have value in Start and End TextBox, since you are calling in Page Load.
If the value is null then make the Parameter nullable.