while (reader.Read())
Keeps executing until there are no more records to read.
myRepeater.DataSource = reader;
myRepeater.DataBind();
Tells the repeater to read all remaining records, and display them. No filter will be applied to those records. When
DataBind()
returns, there are no more records to read.
If you want to filter the results that you're displaying in the repeater, then you need to filter the data source. For example:
private void LoadSchedule()
{
string connString = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connString))
using (SqlCommand comm = new SqlCommand("GetSchedule", conn))
{
SqlDataAdapter adapter = new SqlDataAdapter(comm);
DataTable table = new DataTable();
adapter.Fill(table);
DateTime localDate = DateTime.Now;
myRepeater.DataSource = table.AsEnumerable()
.Where(r => r.Field<DateTime>("PoolActive") < localDate)
.Where(r => r.Field<DateTime>("PoolDisabled") > localDate);
myRepeater.DataBind();
}
}