column to be retrieved from the data base in the DGV
con.Open();
SqlCommand cmd = new SqlCommand("select Faculty_Name from Tb_SCH_Faculty_Details", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
datagridView.Columns[2].HeaderText = dr[2].ToString().Trim();
datagridView.Columns[3].HeaderText = dr[2].ToString().Trim();
datagridView.Columns[4].HeaderText = dr[2].ToString().Trim();
datagridView.Columns[5].HeaderText = dr[2].ToString().Trim();
datagridView.Columns[6].HeaderText = dr[2].ToString().Trim();
dr.Close();
con.Close();
}
when i run message shows index was outside the bound of array.
please help me. i want to use the data reader through data reader i get the Faculty Name from the data base.