private static int SelectPartTest(string connectionString) { List<AdoHome> homes = new List<AdoHome>(); AdoHome home; using (var connection = new SqlConnection(connectionString)) using (var command = new SqlCommand("select Id, Surface, Price, BuildYear, City, Description, AddTime, ProvinceId from Home where BuildYear<@BuildYear;", connection)) { connection.Open(); command.Parameters.AddWithValue("@BuildYear", 2000); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { home = new AdoHome { BuildYear = (int)reader["BuildYear"], City = (string)reader["City"], Description = (string)reader["Description"], Id = (int)reader["Id"], Price = (double)(decimal)reader["Price"], ProvinceId = (int)reader["ProvinceId"], Surface = (int)reader["Surface"] }; homes.Add(home); } reader.Close(); connection.Close(); } return homes.Count; }
private static int SelectJoinTest(string connectionString) { List<AdoHome> homes = new List<AdoHome>(); AdoHome home; using (var connection = new SqlConnection(connectionString)) using (var command = new SqlCommand(@"select h.Id, h.Surface, h.Price, h.BuildYear, h.City, h.Description, h.AddTime, h.ProvinceId, p.Name from Home h inner join Province p on h.ProvinceId=p.Id where p.Code=@Code;", connection)) { connection.Open(); command.Parameters.AddWithValue("@Code", 10); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { home = new AdoHome { BuildYear = (int)reader["BuildYear"], City = (string)reader["City"], Description = (string)reader["Description"], Id = (int)reader["Id"], Price = (double)(decimal)reader["Price"], ProvinceId = (int)reader["ProvinceId"], Surface = (int)reader["Surface"] }; homes.Add(home); } reader.Close(); connection.Close(); } return homes.Count; }