示例#1
0
        public InventoryRecord[] GetInventory()
        {
            // First, get the DataTable from the database.
            InventoryDAL d = new InventoryDAL();

            d.OpenConnection(ConnString);
            DataTable dt = d.GetAllInventoryAsDataTable();

            d.CloseConnection();

            // Now make a List<T> to contain the records.
            List <InventoryRecord> records = new List <InventoryRecord>();
            // Copy the data table into List<> of custom contracts.
            DataTableReader reader = dt.CreateDataReader();

            while (reader.Read())
            {
                InventoryRecord r = new InventoryRecord();
                r.ID      = (int)reader["CarID"];
                r.Color   = ((string)reader["Color"]);
                r.Make    = ((string)reader["Make"]);
                r.PetName = ((string)reader["PetName"]);
                records.Add(r);
            }
            // Transform List<T> to array of InventoryRecord types.
            return((InventoryRecord[])records.ToArray());
        }
示例#2
0
        public void InsertCar(InventoryRecord car)
        {
            InventoryDAL d = new InventoryDAL();

            d.OpenConnection(ConnString);
            d.InsertAuto(car.Color, car.Make, car.PetName);
            d.CloseConnection();
        }