Data Base Design as follows in Ms Access ;
Table Name (Tb_Delcared_Holidays)
HolidayDate Datetime
Reason Text
In Database Records as follows;
HolidayDate Reason
2/22/2013 Holiday
2/25/2013 Holiday
Design as follows;
Faculty Code combobox
Calendar (month Calendar)
Datagrdiview
In combobox all faculty code retrieved from the table and display in to the Combobox.
when i select the calendar that month all date is display in to the datagridview .
when i select the Feburary month in calendar that month all date display in datagridview.
I want to check one condition,when display the date in datagrdiview,
For february month the below two dates is holiday in the Leave Table.
2/22/2013 Leave
2/25/2013 Leave
When i display the date in datagridview,for the above dates in datagridview, the user did not able to select the two dates
Code as follows;
private void Faculty_Available_Calendar_DateChanged(object sender, DateRangeEventArgs e)
{
DGVCalendar.Rows.Clear();
DateTime dt1 = Faculty_Available_Calendar.SelectionStart;
dt1 = new DateTime(dt1.Year, dt1.Month, 1);
DateTime dt2 = dt1.AddMonths(1);
int numDays = (dt2 - dt1).Days;
if (DGVCalendar.RowCount < numDays)
{
DGVCalendar.RowCount = numDays;
}
int row = 0;
while (dt1 < dt2)
{
DGVCalendar.Rows[row].Cells[1].Value = dt1.ToString("dd-MMM-yyyy");
DGVCalendar.Rows[row].Cells[0].Value = true;
if (dt1.DayOfWeek == DayOfWeek.Sunday)
{
DGVCalendar.Rows[row].ReadOnly = true;
DGVCalendar.Rows[row].Cells[0].Value = false;
DGVCalendar.Rows[row].Cells[0].Style.BackColor = Color.Orange;
DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Orange;
DGVCalendar.Rows[row].Cells[2].Style.BackColor = Color.Yellow;
DGVCalendar.Rows[row].Cells[2].Style.ForeColor = Color.Red;
DGVCalendar.Rows[row].Cells[2].Value = "Sunday";
}
sql = "select format(HolidayDate ,'mm dd yyyy') as Holdate, [Reason] from Tb_Delcared_Holidays where Holidaydate = '" + DGVCalendar.Rows[row].Cells[1].ToString() + "'";
dr = GFun.ReadAcessSql(sql);
dr.Read();
if (dr.HasRows == true)
{
DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Blue;
DGVCalendar.Rows[row].Cells[2].Value = dr[0].ToString();
}
dt1 = dt1.AddDays(1);
row++;
}
}
the above code, in the datagridview for the selected month date, display in datagridview,if the
any of the date is holiday in Tb_Declared_Holidays table,
that date should be shown in different color,user should not select the date.
from my above when i run error shows as follows.
Invalid attempt to call read when reader is closed.
the above shows in the below line as follows;
sql = "select format(HolidayDate ,'mm dd yyyy') as Holdate, [Reason] from Tb_Delcared_Holidays where Holidaydate = '" + DGVCalendar.Rows[row].Cells[1].ToString() + "'";
dr = GFun.ReadAcessSql(sql);
dr.Read(); [Invalid attempt to call read when reader is closed]
if (dr.HasRows == true)
{
DGVCalendar.Rows[row].Cells[1].Style.BackColor = Color.Blue;
DGVCalendar.Rows[row].Cells[2].Value = dr[0].ToString();
}
dr.read(); line error shows Invalid attempt to call read when reader is closed.
what is the problem in my above code please help me.