I am getting the sequence numbers of the days of the week from a database and I want to make those days of the week available in the DatePicker
and make the rest unavailable. But all days become unavailable, except for the last (in my case, this is the last day of the year). What am I doing wrong? I took the code from the link as a basis: How to black out specific days of the week (datepicker) [VB] (by the way, it works).
using (OracleConnection conn = new OracleConnection(connectionString))
{
int year = DateTime.Now.Year;
var minDate = DateTime.Now;
var maxDate =new DateTime(year, 12, 31);
string r;
string st = comboBox2.SelectedItem.ToString();
string sql3 = "select distinct id_week from timetable,masters where
timetable.id_mas=masters.cod and masters.fio = '" + st + "'";
using (OracleCommand command = new OracleCommand(sql3, conn))
{
OracleDataReader reader3 = command.ExecuteReader();
while (reader3.Read())
{
r = reader3[0].ToString();
for (var d = minDate; d <= maxDate> d; d = d.AddDays(1))
{
if ((int)d.DayOfWeek != Convert.ToInt32(r))
{
dateTimePicker1.BlackoutDates.Add(new CalendarDateRange(d));
}
}
}
reader3.Close();
}
}