///<summary>Updates database based on the values in ListSupplyAll.</summary> private void saveChangesToDBHelper() { //Get all supplies from DB to check for changes.----------------------------------------------------------------- List <Supply> ListSupplyAllDB = Supplies.GetAll(); //Itterate through current supply list in memory----------------------------------------------------------------- for (int i = 0; i < ListSupplyAll.Count; i++) { //find DB version of supply to pass to UpdateOrInsertIfNeeded Supply supplyOriginal = null; for (int j = 0; j < ListSupplyAllDB.Count; j++) { if (ListSupplyAll[i].SupplyNum != ListSupplyAllDB[j].SupplyNum) { continue; //not the correct supply } supplyOriginal = ListSupplyAllDB[j]; break; //found match } Supplies.UpdateOrInsertIfNeeded(supplyOriginal, ListSupplyAll[i]); //accepts null for original. } //Update inmemory list to reflect changes. ListSupplyAll = Supplies.GetAll(); }