private List<string> GetAllFieldValues(string p) { List<string> field_values = new List<string>(); string connectionString = ConfigurationManager.ConnectionStrings["SchoolContext"].ConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(); con.Open(); cmd.CommandText = "SELECT " + p + " from tbl_student where institutionid=" + Convert.ToInt32(Session["institutionId"].ToString()); cmd.Connection = con; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { if (p == "dateofadmission" || p == "dateofbirth") field_values.Add(Convert.ToDateTime(dr[0].ToString()).ToShortDateString()); else field_values.Add(dr[0].ToString()); } } else { } } return field_values; }