I am really stuck on how to solve this problem.
public bool DeleteVegetationZone(ref Assessment objAssessment, int VegetationZoneIDToDelete, string UserFullname, ref string ErrorMessage) { string RowFilter = @"VegetationZoneID=" + Convert.ToString(VegetationZoneIDToDelete); Assessment.tblVegetationZoneRow[] VegetationZoneRows = (Assessment.tblVegetationZoneRow[])objAssessment.tblVegetationZone.Select(RowFilter); if ((VegetationZoneRows != null) && (VegetationZoneRows.Length != 0)) { if (VegetationZoneRows.Length == 1) { if (VegetationZoneRows[0].VegetationZoneID > 0) { VegetationZoneRows[0].UpdatedBySystemUser = UserFullname; VegetationZoneRows[0].SaveType = (int)EnumCollection.SaveType.RemoveOnly; } else { VegetationZoneRows[0].Delete(); objAssessment.AcceptChanges(); } //tblThreatenedSpeciesSubzone var list = objAssessment.tblThreatenedSpeciesSubzone.Rows.ToList(); for (int i = 0; i < objAssessment.tblThreatenedSpeciesSubzone.Count; i++) { foreach (Assessment.tblThreatenedSpeciesSubzoneRow ThreatenedSpeciesSubzoneRow in objAssessment.tblThreatenedSpeciesSubzone.Rows) { if (ThreatenedSpeciesSubzoneRow.VegetationZoneID == VegetationZoneIDToDelete) DeleteThreatenedSpeciesSubzone(ref objAssessment, ThreatenedSpeciesSubzoneRow.ThreatenedSpeciesZoneID, UserFullname, ref ErrorMessage); } } UpdateSpeciesGeoHabitatSurveyTime(ref objAssessment, UserFullname, ref ErrorMessage); } else { //Cannot have more than one row with same key ErrorMessage = "Error: More than one record found - Vegetation zone ID = " + Convert.ToString(VegetationZoneIDToDelete); return false; } } else { //Must have at least one row with same key ErrorMessage = "Error: Record not found - Vegetation zone ID = " + Convert.ToString(VegetationZoneIDToDelete); return false; } return true; }
I have a problem "tblThreatenedSpecies Subzone" to delete, it throws an exception "An error has occurred. The collection has been modified, the enumeration operation may not be executed"
var list = objAssessment.tblThreatenedSpeciesSubzone.Rows.ToList(); for (int i = 0; i < objAssessment.tblThreatenedSpeciesSubzone.Count; i++) { foreach (Assessment.tblThreatenedSpeciesSubzoneRow ThreatenedSpeciesSubzoneRow in objAssessment.tblThreatenedSpeciesSubzone.Rows) { if (ThreatenedSpeciesSubzoneRow.VegetationZoneID == VegetationZoneIDToDelete) DeleteThreatenedSpeciesSubzone(ref objAssessment, ThreatenedSpeciesSubzoneRow.ThreatenedSpeciesZoneID, UserFullname, ref ErrorMessage); } }
I tried to change based on what you guys advised, but now I have a different exception.
Hope someone directs me on the right path.
Usher source share