예제 #1
0
        public List <NewCar> GetAllInventoryAsList()
        {
            // Здесь будут находиться записи.
            List <NewCar> inv = new List <NewCar>();

            // Подготовка объекта команды.
            string sql = "select * from Inventory";

            using (SqlCommand command = new SqlCommand(sql, _sqlConnection))
            {
                SqlDataReader dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    int?   carId   = dataReader["CarId"] as int?;
                    string color   = dataReader["Color"] as string;
                    string make    = dataReader["Make"] as string;
                    string petName = dataReader["PetName"] as string;
                    NewCar aNewCar = new NewCar
                    {
                        CarId   = carId.HasValue ? carId.Value : 0,
                        Color   = color ?? "None",
                        Make    = make ?? "None",
                        PetName = petName ?? "None"
                    };
                    inv.Add(aNewCar);
                }
                dataReader.Close();
            }

            return(inv);
        }
예제 #2
0
 public void InsertAuto(NewCar car)
 {
     InsertAuto(car.CarId, car.Make, car.Color, car.PetName);
 }