I am using multiple parameter for binding gridview. i used following code for binding.
string constr = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
//string query = "select * from bug_details where (auditor_name=@auditor_name or @auditor_name='')and(datee=@date or @date='')and((datee between @from and @to) or @from='' and @to='')";
string query = "select * from bug_details where (auditor_name=@auditor_name or @auditor_name='')and (datee=@date or @date='')and(datee between (@from or @from='') and (@to or @to=''))";
SqlCommand cmd = new SqlCommand(query);
cmd.Parameters.AddWithValue("@auditor_name", ddlauditorsearch.SelectedIndex > 0 ? ddlauditorsearch.SelectedValue : "");
cmd.Parameters.AddWithValue("@date", txtfromdate.Text.Trim());
cmd.Parameters.AddWithValue("@from", txtfromdate.Text.Trim());
cmd.Parameters.AddWithValue("@to", txttodate.Text.Trim());
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlDataAdapter da = new SqlDataAdapter())
{
cmd.Connection = con;
da.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
}
}
}
if i enter date in txtfromdate text box in will get record from particuler date and if i enter date in both the text box it will get records between these two date and one more two text box may be empty also.
How can i achevie this........