protected void btnSearch_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_ConnStr)) { using (SqlCommand cmd = new SqlCommand("SELECT * FROM Orders WHERE ORD_Date BETWEEN @From AND @To", con)) { using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { cmd.Parameters.AddWithValue("@From", Convert.ToDateTime(this.txtfromdate.Text)); cmd.Parameters.AddWithValue("@To", Convert.ToDateTime(this.txttodate.Text)); DataSet ds = new DataSet(); da.Fill(ds); GridViewOrdersBuyer.DataSource = ds; GridViewOrdersBuyer.DataBind(); } } } }
private void BindGridView() { SqlConnection con1 = new SqlConnection(_ConnStr); DataTable dt = new DataTable(); con1.Open(); SqlCommand cmd = new SqlCommand("select *from Orders where ORD_BuyerUserID = '" + Session["M_Subscriber_UserID"] + "' ", con1); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); GridViewOrdersBuyer.DataSource = dt; GridViewOrdersBuyer.DataBind(); con1.Close(); }