Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 748
  • 1.2k
  • 58.8k

Sorting data within date range

Mar 28 2024 1:23 PM

Hello Team,

In my window application, am using dataGridview table and dateTimepicker to sort data in date range even though it is working but if I tried sorting only 2023 year data it end up as well sorting 2022 year data.

 public void SortBaptismalCandidate()
        {
            int i = 0;
            dataGridView3.Rows.Clear();
            cn.Open();
            cm = new SqlCommand("Select * from tblBaptismal where SDate between'" + BaptismalDt1.Value.ToString("dd-MM-yyyy") + "'and'" + BaptismalDt2.Value.ToString("dd-MM-yyyy") + "%'", cn);
            dr = cm.ExecuteReader();
            while (dr.Read())
            {
                i++;
                dataGridView3.Rows.Add(i, dr["id"].ToString(), dr["SDate"].ToString(), dr["bFName"].ToString(), dr["bLName"].ToString(), dr["bGender"].ToString(), dr["bDOB"].ToString(), dr["bPhoneNo"].ToString(), dr["bLocation"].ToString(), dr["bFatherName"].ToString(), dr["bMotherName"].ToString(), dr["bPhoneNumber"].ToString());
            }
            dr.Close();
            cn.Close();
        }


Answers (2)