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; }
this is my ADO.NET code how can i convert this one to linq i have an idea to change linq but i don't know pass the parameter dynamically.