Question How can I code so records filtered between two dates in DataGridView display in the Textboxs?

Godis

Member
Joined
Jul 31, 2019
Messages
19
Programming Experience
Beginner
I am working on a project where I want records filtered between two given dates in the datagridview display in the form textboxes accordingly.

I have tried all I could but it is not working. I have also tried to place a label control as alternative to total up the filtered records on the datagridview but I couldn't code to make it successful.

Please I appreciate if someone can help me out on these two problems.

I hereby attach my filter button code for correction.

Thanks as I look forward for correction
C#:
 private void btnSearch_Click(object sender, EventArgs e)
        {
            
            con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
            con.Open();

            SqlDataAdapter da = new SqlDataAdapter("Select * From FarmHistory Where Date Between '"+fromDateTimePicker.Value.ToString()+"' And '"+toDateTimePicker.Value.ToString()+"'", con);
            DataTable dt = new DataTable();
            da.Fill(dt);       
            farmHistoryDataGridView.DataSource = dt;                         
          }
 
cmd = new SqlCommand("the query", con)
 
Back
Top Bottom