public class ContinentDataAccessLayer { public static List<continent> GetAllContinents() { List<continent> listContinents = new List<continent>(); string CS = ConfigurationManager.ConnectionStrings["con"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("Select CountryName from country", con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Continent continent = new Continent(); continent.ContinentId = Convert.ToInt32(rdr["CountryID"]); // System.IndexOutOfRangeException: CountryID continent.ContinentName = rdr["CountryName"].ToString(); listContinents.Add(continent); } } return listContinents; } }
Select CountryName, CountryID from country
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)