Oh boy Narasiman,
You are getting stress about your homework aren't you, that you cannot see what you are doing.
You didn't add the faculty code to the datagrid, so how will it display?
you should have something like this in you for loop;
DGVCalendar.Rows[irows].Cells[2].Value = cb_Faculty_Code.Text;
By the way Text is a string, you do not need to convert to string in your query.
Also what is the purpose of the irows variable, why are you incrementing is outside the for loop?
Here is the optimized code for you.
private void cb_Faculty_Code_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
sql = "Select [Available_date],[Session1],[Session2],[Session3],[Session4] from Tb_Faculty_Availability where Faculty_code = '" + cb_Faculty_Code.Text + "'";
dr = GFun.ReadAcessSql1(sql);
while (dr.Read())
{
for (int irows = 0; irows < DGVCalendar.RowCount; irows++)
{
DGVCalendar.Rows[irows].Cells[2].Value = cb_Faculty_Code.Text;
DGVCalendar.Rows[irows].Cells[2].Value = dr[0].ToString();
DGVCalendar.Rows[irows].Cells[4].Value = dr[1].ToString();
DGVCalendar.Rows[irows].Cells[5].Value = dr[2].ToString();
DGVCalendar.Rows[irows].Cells[6].Value = dr[3].ToString();
DGVCalendar.Rows[irows].Cells[7].Value = dr[4].ToString();
}
}
dr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error");
return;
}
}
I hope you get good grade on your homework.
Regards
Jegan